File_column and Thumbnails


#1

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?


#2

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 :(.

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

Nicholas P. Mueller


#3

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