perl: September 2007 Archives

Creating thumbnails on the fly under FastCGI

| | Comments (0)
A while ago I wrote about the problems I was having with trying to get Image::Magick to create thumbnails on the fly whilst running under FastCGI. Well, I was right then that the problem lay in the fact that FCGI ties STDOUT whilst Image::Magick also wants to access STDOUT to write to. I spent a couple more hours trying to figure out how to untie STDOUT, do the Image::Magick->Write to STDOUT then re-attach it to FCGI. No luck. The FCGI->Detach method didn't do it. Under hood was too complex for me to understand.

I retreated and looked at GD again. Similar problems, as well as a messier interface. Then I had a gander around seach.cpan.org and picked up on Imager. Thanks to the handy rating stars on the search pages it looked promising. And really, it is a breath of fresh air: well documented, developer-friendly interface, myriad options and ways to play with images (including the scale() method which automatically scales in proportion). And, crucially, you can write() your images to a scalar variable, which means you can then print that scalar and FCGI will scoop it up and print it out like any other print statement.

Job done: I can now make thumbnail images on the fly and send them back to the browser under FastCGI by dropping Image::Magick for the new and very impressive Imager.

About this Archive

This page is a archive of entries in the perl category from September 2007.

perl: May 2007 is the previous archive.

perl: November 2007 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.21-en