Re: RMagick at dreamhost

Constantin Gavrilescu
Tue, 06 Feb 2007 02:23:28 -0000

Tim Hunter wrote:
> Constantin Gavrilescu wrote:
>> I''m getting the crazy error "undefined method
`resize_to_fit'' for
>> #<Magick::Image:0x41b74904>"
>>
>> I have RMagick on dreamhost, but no resize_to_fit method? Am I missing
>> something?
>
> You may be missing a sufficiently recent version of RMagick. The
> resize_to_fit method was added in version 1.11.0. What version of
> RMagick is installed? Try this:
>
> ruby -r RMagick -e"puts Magick::Long_version"
>
> If the version is older than 1.11.0, you can add it yourself. The
> Image#resize_to_fit method is extremely simple to write. The code for it
> in RMagick.rb is this:
>
>     def resize_to_fit(cols, rows)
>         change_geometry(Geometry.new(cols, rows)) do |ncols, nrows|
>             resize(ncols, nrows)
>         end
>     end

Indeed on my host (clamato.dreamhost.com) I have Rmagick 1.6.0, a 2004
build.
This is RMagick 1.6.0 ($Date: 2004/08/18 23:22:36 $) Copyright (C) 2004
by Timothy P. Hunter

This is my first public rails website and I''m still learning. Your
solution was perfect. I just added this on top of my model.rb. It needed
a small modification, so I''m posting this here, maybe to help another
newbie.

# quick hack for dreamhost for an old version of RMagick
class Magick::Image
  def resize_to_fit!(cols, rows)
    change_geometry(Magick::Geometry.new(cols, rows)) do |ncols, nrows|
      resize!(ncols, nrows)
    end
  end

  def resize_to_fit(cols, rows)
    change_geometry(Magick::Geometry.new(cols, rows)) do |ncols, nrows|
      resize(ncols, nrows)
    end
  end
end