Forum: Ruby on Rails file_column 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.
A7db9ec803b5895ae5f916a74e2db329?d=identicon&s=25 HH (Guest)
on 2006-04-24 00:32
(Received via mailing list)
I see that the SVN version of the excellent file_column plug-in can
create
thumbnails using the url_for_image_column helper.

This uses Rmagick to create the thumbnail... Quick question...

Let's say the file is a TIFF image - can the helper create a JPG version
of
the thumbnail for display in the browser?

Curious if the plug-in can handle that transform with some creative use
of
the options. Any ideas before I hack up the plug-in code myself?
99c89698aa4661ec1750c0fb9b798eab?d=identicon&s=25 Nicholas P. Mueller (Guest)
on 2006-04-24 08:07
(Received via mailing list)
I believe it can using Rmagick.  If you read the rdoc documentation for
file_column you can interact with Magick directly.  I don't have it in
front of me right now so I can't be more help :(.

<rant>A good, integrated and well-documented image manipulation library
is one of a few things I miss from my PHP days.</rant>

Nicholas P. Mueller
807e34b31d5463a9ac05d41458a9e537?d=identicon&s=25 Al Evans (al-evans)
on 2006-04-24 13:52
HH wrote:
> I see that the SVN version of the excellent file_column plug-in can
> create
> thumbnails using the url_for_image_column helper.
>
> This uses Rmagick to create the thumbnail... Quick question...
>
> Let's say the file is a TIFF image - can the helper create a JPG version
> of
> the thumbnail for display in the browser?
>
> Curious if the plug-in can handle that transform with some creative use
> of
> the options. Any ideas before I hack up the plug-in code myself?

Yes, you can do that. Actually, you shouldn't have to do much hacking --
RMagick (or rather, ImageMagick/GraphicsMagick behind it) can determine
what kind of image you feed it.

Here's the code I use to convert an uploaded photo to a thumbnail that's
96 pixels in its longest dimension:

  def write_photo_file(photo_data)
    img = Image.from_blob(photo_data)
    img.first.strip!.change_geometry("96x96") { |cols, rows, img|
      img.resize!(cols, rows)
    }
    img.write(User.photo_file_name_for(self.id)) { self.quality = 50 }
  end

Not much to it....

--Al Evans
This topic is locked and can not be replied to.