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. As its input, FastImage Resize can take a URI, a filename, or an IO object (or anything that responds to :read). If you do not supply an output filename in the :outfile option, FastImage Resize will return you a Tempfile object. This will be unlinked when it is finalized during garbage collection. FastImage Resize relies on "RubyInline":https://github.com/seattlerb/rubyinline for compiling and managing the C extension code. h4. Incompatible API change Version 2.0.0 and above Note that the parameters for version 2.0.0 have changed, the output filename is no longer the second parameter. See the examples. h2. Examples
require 'fastimage_resize'
FastImage.resize("http://stephensykes.com/images/ss.com_x.gif", 100, 20, :outfile=>"my.gif")
=> nil
outfile = FastImage.resize("nonexistentfile.png", 50, 50)
=>FastImage::ImageFetchFailure: FastImage::ImageFetchFailure
outfile = FastImage.resize("afile.png", 50, 150)
=> #
File.open("afile.png", "r") {|f| FastImage.resize(f, 100, 100)}
=> #
h2. Installation
First check the requirements section below.
h4. Gem
gem install fastimage_resize
h4. Rails
Install the gem as above, and for Rails 2 configure it in your environment.rb file as below:
...
Rails::Initializer.run do |config|
...
config.gem "fastimage_resize"
...
end
...
For Rails 3, add this to your Gemfile:
gem 'fastimage_resize'
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:
ENV['INLINEDIR'] = RAILS_ROOT + "/tmp" # for RubyInline
Then you're off - just use FastImage.resize() in your code as in the examples.
h2. Requirements
* RubyInline
gem install RubyInline
* FastImage
gem install fastimage
* 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.
sudo port install gd2
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 '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
h2. Licence
MIT, see file MIT_LICENCE
h2. Author
Stephen Sykes, @sdsykes