Super simple image resizing
December 3rd, 2007
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:
w = 100
h = 100
s = SfsResize.new("in.gif")
s.resize_and_write_to_file("out.gif", w, h)
Severely untested, but good fun nevertheless.
14 Responses to “Super simple image resizing”
Sorry, comments are closed for this article.






For the user and company avatars in RailsCollab, i just installed the GD2 bindings for ruby and ended up with this relatively simple code.
Granted, could be simpler. But it works. ;)
C’mon, isn’t Super Simple good enough? Can’t you express yourself without “f*” and “goddam”? Grow up!
I think it’s you who should learn to read. What is this crap about Super simple? Are you a little girl who is afraid to bother your parents with your sailor language? Come on!! Grow up and don’t read too much or you could get offended.
Learn To Write: clearly you have never had to deal with image resizing or any of the Magicks.
I never really knew about libgd, so thanks for the little write-up.
Batou, there is a time and a place for cussing, but if you do it with everything you say and throw around insults at people you’re mostly just hurting yourself. It makes you look inarticulate and is very unprofessional.
Hi Damien,
I presume this is going to work on Linux as well?
James Urquhart: f** simple! Much better for production. Inline has lovely error reporting ;)
Stuart Eccles: will work no problem!
Super f*ing awesome.
ImageMagick is a pain to install?
apt-get install imagemagick librmagick-ruby
Steve: Yes, because when you do ‘apt-get install imagemagick librmagick-ruby’ it still doesn’t work. Not on my system, anyway.
f** could mean anything! I for one read it as “fancy”.
Anyway, this looks awesome. Someone should add it as a processor for attachment_fu…
You could say what all the funny kids are saying these days: It’s Sofa King Simple!
Nice utility, I’ve been using ImageScience with pleasant results, but I’m really looking forward to trying this out. Not only will my code base shrink I can eliminate the one compiled from source application on my servers.
Justin: Of course… it was actually super ‘fascinating’ .
Mak: Ha. I’m using it in a little merb app and it’s so much faster than imagemagick. In fact, here (attachment_pu.rb) is the little merb lib which I’m using for attachments. Very simple, S3 and more will be added as time goes on.
Thanks for this. In fact I just needed to find the dimensions of my images, but your code proved very helpful – I modded it to just return the dimensions. I made an entry in my blog ( http://pennysmalls.com ) with the code.