Forum: Ruby on Rails RMagick and thumbnails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ae03102311939454d2b7f1ca3139fd97?d=identicon&s=25 Lindsay Boyd (Guest)
on 2006-03-27 21:43
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:in `make_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
9c0eebc506c56c64dc616cdf123fa671?d=identicon&s=25 Chris Chris (aboulafia)
on 2006-03-27 22:24
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 : http://www.ruby-forum.com/topic/59545#new
Ae03102311939454d2b7f1ca3139fd97?d=identicon&s=25 Lindsay Boyd (Guest)
on 2006-03-27 22:33
Christophe Gimenez 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 : http://www.ruby-forum.com/topic/59545#new

I would prefer to store the images in the database - but I'll definitely
look into mini_magick. Thanks.
807e34b31d5463a9ac05d41458a9e537?d=identicon&s=25 Al Evans (Guest)
on 2006-03-28 02:53
Lindsay Boyd 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
This topic is locked and can not be replied to.