Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
101 lines (66 sloc) 2.11 KB

FastImage Resize

FastImage Resize is an extremely light solution for resizing images in ruby by using libgd

FastImage Resize will resize gifs, jpegs, and png files.

It uses resampling to get good looking results.

And it doesn’t rely on installing external heavy libraries such as RMagick (which relies on ImageMagick or GraphicsMagick) or ImageScience (which relies on FreeImage).


  require 'fastimage_resize'

  FastImage.resize("", "my.gif", 100, 20)
  => 1

The file my.gif is created locally, containing the resized image.


First check the requirements section below.


  sudo gem install sdsykes-fastimage_resize -s


Install the gem as above, and configure it in your environment.rb file as below:

... do |config| ... config.gem "sdsykes-fastimage_resize", :lib=>"fastimage_resize" ... end ...

You may also need this in your environment.rb so that the rails process puts the compiled C code in a place it can access:

ENV['INLINEDIR'] = RAILS_ROOT + "/tmp"  # for RubyInline

Then you’re off – just use FastImage.resize() in your code as in the examples.


  • RubyInline

  sudo gem install RubyInline

  • FastImage

  sudo gem install sdsykes-fastimage -s

  • Libgd


Libgd is commonly available on most unix platforms, including OSX.



Because of the way that libgd works, gif files that have transparency may not always come through with the transparency perfectly retained.


You’ll need to ‘sudo gem install fakeweb’ to be able to run the tests