Search code examples
ruby-on-railsrubyimagemagickrmagick

changing image file name rmagick


The Rmagick docs aren't the clearest, i've tried everything but it doesn't like it? Maybe im misunderstanding how Magick::Info works?

http://www.imagemagick.org/RMagick/doc/info.html

def crop_photo(url, x, y, w, h)
 image =  Magick::ImageList.new
 urlimage = open(url)
 format = url.split('/')[-1].strip.split('?')[0].strip
 image.from_blob(urlimage.read)
 crop = image.crop(x,y,w,h)
 image = crop.to_blob
    image.filename = format #doesn't work
    self.filename = format  #doesn't work
end

help is greatly appreciated


Solution

  • In order to save Image or ImageList you use write method:

    image.write(new_filename)