Forum: Ruby on Rails RE: Rmagick Howto?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
F01c3ff32fee35d911e81c172a005012?d=identicon&s=25 Tom (Guest)
on 2005-12-08 07:03
(Received via mailing list)
Here's some code to take an image and create one that has a maximum
dimension of 100 pixels:

    img_big = Magick::Image.from_blob(
    img_smaller = img_big.change_geometry("100x100") { |cols, rows, img|
      img.resize(cols, rows)
    thumbnail_column_data = img_smaller.to_blob { self.quality = 75 }

Remember to always follow up the RMagick calls with:

    fDisabled = GC.enable
    GC.disable if fDisabled

Otherwise Ruby will soon run out of memory.
Eecd295cdec2454c66e2015036a39408?d=identicon&s=25 Scott Nj (scottnj)
on 2005-12-08 18:09
I am trying to add a thumbnail to the image upload example in the "Agile
Web Development with Rails" book.

I added a blob column "thumbnail" to the table.
Added "require 'RMagick'" to the bottom of environment.rb

My model looks like:
class Picture < ActiveRecord::Base
  belongs_to :picture_category
  validates_format_of :content_type, :with => /^image/,
                :message => "--- you can only upload pictures"

  def picture=(picture_field) = base_part_of(picture_field.original_filename)
    self.content_type = picture_field.content_type.chomp =

    img_big = Magick::Image.from_blob(
    img_smaller = img_big.change_geometry("100x100") { |cols, rows, img|
      img.resize(cols, rows)
    self.thumbnail = img_smaller.to_blob { self.quality = 75 }

  def base_part_of(file_name)
    name = File.basename(file_name)
    name.gsub(/[^\w._-]/, '')

The error I am getting is:
undefined method `change_geometry' for [ JPEG 1024x768 DirectClass 8-bit

I am sure there are probably mutiple mistakes. What am I doing wrong
(besides error recovery and validation, one step at a time)?
1c46e952a61c99d9eae4f21037a088fd?d=identicon&s=25 anatol.pomozov (Guest)
on 2005-12-08 18:33
(Received via mailing list)
Try this code

    img = Magick::Image.from_blob(self.content_data).first

    img.change_geometry!('140x200') { |cols, rows, i|
      i.resize!(cols, rows)

    self.thumbnail = img.to_blob

This topic is locked and can not be replied to.