Ruby/Rails - RMagick, Upload and Resize without a model

I'm fairly new to rails, but I think I can help you. I think you wan to use RMagick's from_blob flunction. It takes an image as binary data and gives you an Magick Image object. Like so:

image = Magick::Image.from_blob(@params['picture_file'].read).first

Then you can manipulate it. For instance resample:

thumb = image.sample(200, 200)

Then write to file:


hope this helps


You can find the rMagick Docs here:

There are a number of ways to resize an image, but I have been using change_geometry to maintain aspect ratio. I don't remember the exact syntax, but the docs should be enough to get you on your way.

(I'm not sure if this works, but it should be close) image = Magick::Image.from_blob(@params['picture_file'].read).first image.change_geometry("400x300"){|cols, rows, i| i.resize! (cols,rows) }