Skip to content
Find file
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).

Examples


  require 'fastimage_resize'

  FastImage.resize("http://stephensykes.com/images/ss.com_x.gif", "my.gif", 100, 20)
  => 1

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

Installation

First check the requirements section below.

Gem


  sudo gem install sdsykes-fastimage_resize -s http://gems.github.com

Rails

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


... Rails::Initializer.run 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.

Requirements

  • RubyInline

  sudo gem install RubyInline

  • FastImage

  sudo gem install sdsykes-fastimage -s http://gems.github.com

  • Libgd

See http://www.libgd.org/

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

Documentation

http://rdoc.info/projects/sdsykes/fastimage_resize

Caveats

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

Tests

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

References

Something went wrong with that request. Please try again.