RMagick and thumbnails

I’ve based my code on the Agile example for uploading files, pages
362-365. I’ve successfully loaded the Picture object to the database,
but I come unstuck when trying to replicate this for a thumbnail version
of the original image:

      thumbnail = Thumbnail.new
      thumbnail.name = 'thumbnail_' + @picture.name.to_s
      thumbnail.content_type = @picture.content_type
      thumbnail.data = @picture.data
      thumbnail.make_thumbnail
      thumbnail.save

I get the following error on the make_thumbnail method:

ArgumentError (can’t decode image):
/app/models/thumbnail.rb:11:in read_inline' /app/models/thumbnail.rb:11:inmake_thumbnail’

Here’s the Thumbnail model:

require ‘RMagick’
include Magick

def make_thumbnail
img = Image.read_inline(self.data)

end

What do I have to do to thumbnail.data to get RMagick to read it?

Lindsay

You should go the easy way by :

  • using mini_magick instead rmagick (less memory foot print)
  • storing your pictures on disk instead on db

In that case, handling file upload is quite simple.

Look here : Image manipulation/resizing server-side? - Rails - Ruby-Forum

Christophe G. wrote:

You should go the easy way by :

  • using mini_magick instead rmagick (less memory foot print)
  • storing your pictures on disk instead on db

In that case, handling file upload is quite simple.

Look here : Image manipulation/resizing server-side? - Rails - Ruby-Forum

I would prefer to store the images in the database - but I’ll definitely
look into mini_magick. Thanks.

Lindsay B. wrote:

What do I have to do to thumbnail.data to get RMagick to read it?

According to my reading of the RMagick docs, read_inline takes a
Base64-encoded string. Is your @picture.data encoded, or raw?

–Al Evans