h1. FastImage Resize

h4. 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).

FastImage Resize uses *Libgd*, which is commonly available on most unix platforms, including OSX.  It is very likely that you already have this software installed on your server.

h2. Examples

<pre>
<code>
  require 'fastimage_resize'

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

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

h2. Installation

First check the requirements section below.

h4. Gem

<pre>
<code>
  sudo gem install fastimage_resize
</pre>
</code>

h4. Rails

Install the gem as above, and for Rails 2 configure it in your environment.rb file as below:
<pre>
<code>
...
Rails::Initializer.run do |config|
  ...
  config.gem "fastimage_resize"
  ...
end
...
</code>
</pre>

For Rails 3, add this to your Gemfile:

<pre>
<code>
gem 'fastimage_resize'
</code>
</pre>

For any Rails version, 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:

<pre>
<code>
ENV['INLINEDIR'] = RAILS_ROOT + "/tmp"  # for RubyInline
</code>
</pre>

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

h2. Requirements

* RubyInline

<pre>
<code>
  sudo gem install RubyInline
</pre>
</code>

* FastImage

<pre>
<code>
  sudo gem install fastimage
</pre>
</code>

* Libgd

See "http://www.libgd.org/":http://www.libgd.org/

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

On OSX, if you have "macports":http://www.macports.org/ you can use.

<pre>
<code>
  sudo port install gd2
</code>
</pre>

It is also available in "homebrew":http://github.com/mxcl/homebrew (search for gd), and "fink":http://www.finkproject.org/ (try fink install gd2 gd2-bin).

h2. Documentation

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

h2. Caveats

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


h2. Tests

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

h2. References

* "http://blog.new-bamboo.co.uk/2007/12/3/super-f-simple-resizing":http://blog.new-bamboo.co.uk/2007/12/3/super-f-simple-resizing