Apr 08

Whatever web based application you will be working with you will almost certainly need to generate image thumbnails on-the-fly. We were dealing with this issue when we start to develop our own content management system few years ago. Users willing to publish pictures on the web will almost always upload their pictures from digital camera. Those are however high-resolution photos not very suitable for web. You need to scale them down to appropriate size. But how?

There are two ways to do it. One is to automatically scale picture when user uploads it or upload original picture and scale it down when the picture is displayed. I like the last option, because it gives you freedom of use. You can link to original high-resolution version or you can scale it down to whatever size you like.

Creating thumbnail is easy as creating link to an image e.g. /thumb/images/photo.jpg?w=150&h=150 . Yes you can specify width and height of image directly in the link and script will give you picture of appropriate size.

I was working with this approach over years in PHP. Now I created similar thumbnail generator in Ruby on Rails.

Download RoR thumbnail generator here.

The Ruby on Rails version works as good as PHP one in our CMS. It supports JPG, PNG and GIF pictures. It is just single controller with easy three steps install. It has cache build in so all the scaled down pictures are saved for later use which saves future processing time and promptly delivers resized picture.

If you have online gallery, picture library or any other place where you need to scale down pictures feel free to use RoR thumbnail generator.

I will be also happy to hear about any suggestions or improvements.