Would you like to instantly generate thumbnails of any size?
Ruby thumbnail generator is a simple script which is ideal to use in your Ruby on Rails application to quickly generate thumbnails of any proportions. Just set width and height and get image.
Features
- support for JPEG, PNG and GIF formats
- custom width and height (set ?w=250&h=300 in pixels in the URL)
- calculate proper proportions
- cache resized images
Download it here
Installation:
1. copy "thumb_controller.rb" into your /controllers/ directory
2. edit /config/routes.rb and add this line:
map.connect "thumb/*specs", :controller => "thumb", :action => "index"
3. create directory /imagelib/ in RoR's /public/ directory and
/image_cache/ inside /imagelib/ directoory
Now you can call /thumb/photo.jpg?w=400&h=350 and you will
see resized picture "photo.jpg". photo.jpg should be stored in
/public/imagelib/ directory. Off course you can change directory
structure if you wish just don't forget to edit thumb_controller.rb
than.
Requirements
Ruby/GD2 and
Thomas Boutell's GD 2 graphics library Tip:
Instead of CGI you can use:
send_file(cachedpicfile, :type => 'image/jpeg', :disposition => 'inline') and delete
render :nothing => true by
Simone Romano