New Bamboo Web Development

Bamboo blog. Our thoughts on web technology.

Super simple image resizing

by Damien Tanner

Everyone knows ImageMagick is a goddam pain to install and a beast of a library to use for simple image resizing and cropping. ImageScience is on the way, but it's still easy to bump into issues compiling Freeimage. If all you want to do is resize (and crop) libgd is even more lightweight (and tiny enough to do away with DarwinPorts). With a bit of inline C we can do some really lean image resizing.

SfsResize (sfs_resize.rb) is a super simple image resizer. Compile libgd in a few minutes (there is an OS X how-to) and then use it like this:

1 w = 100
2 h = 100
3 s = SfsResize.new("in.gif")
4 s.resize_and_write_to_file("out.gif", w, h)

Severely untested, but good fun nevertheless.