FloydATC has asked for the wisdom of the Perl Monks concerning the following question:

I looked around on CPAN for modules that could generate thumbnail images on-the-fly with Apache 2.x, but all I could find except generic thumbnailers was Apache::GD::Thumbnail. Unfortunately, even after MINUTES of testing I was unable to make it work under Apache2. I concluded that this was probably because Apache2 is quite different from Apache 1.x, and proceeed to roll my own module.

Now, it works. It installs into httpd.conf like so:

<LocationMatch '\.jpg\$\d+'> SetHandler perl-script PerlHandler Apache2::Thumbnail </LocationMatch>
The idea is this: http://foo.bar/original.jpg$100 yields a thumbnail image that fits inside a 100x100 box. It works perfectly, using Image::Magick and a cache directory for performance.

I would have preferred to use the "?" character over "$" ofcourse, but I found no obvious way to match this in httpd.conf; I could pass ALL jpg images through my handler ofcourse, but that would hurt performance on a busy system. Suggestions would be MOST welcome.

My real issue though is this: The working name for my module is, as you can see, "Apache2::Thumbnail"...

I have never uploaded to CPAN. I don't know if this is a good name, and I certainly don't know if the module is "good enough" to take up this spot in the namespace.

Is there a place within the monastery where I can perhaps post the module to have it audited/reviewed/flamed/ridiculed? I don't want to make a total a^H...BEHIND of myself by uploading a module people warn each other about in years to come.

For now, the script can be found here: http://floyd.atc.no/Programming/Perl/Apache2::Thumbnail/ and the module can be seen in action here: http://floyd.atc.no/Fun%20stuff/Images/

Replies are listed 'Best First'.
Re: Before uploading my module...
by philcrow (Priest) on May 22, 2007 at 19:29 UTC
    First, don't fret about uploading your module. It works and is compact. The code is easy to read. Rest assured that CPAN has modules of less quality and utility. The name is fine, simple and direct. If others want to improve it, they can send code. If you could describe it in more detail, you might try Apache2::Thumbnail::Descriptor.

    That said, I have some thoughts. I would go ahead and use a PerlSetVar to control the cache location. People are particular about where apache can write.

    I see why you want to trap the thumbnail size in the location match, but it feels a bit odd. The other module you refer to uses a location for which all images will be scaled to the same size. Different sizes would just need different location matches. As long as their aren't more than a couple of thumbnail sizes that seems like a small burden to me. A set var in each one controls the size. That seems less magical to me, and therefore more appealing. So you could say http://example.com/images/thumbs/100/original.jpg. Everything before the file name would be matched and the file is the name of the jpg which you look for in the original image path.

    Those are just my first impressions. Don't let them disuade you from uploading it so others can try it.

    Phil

    The Gantry Web Framework Book is now available.
Re: Before uploading my module...
by strat (Canon) on May 23, 2007 at 08:56 UTC

    I'd set the filehandle to binmode to make it work under Win32 as well, slurp the file, and use open with three params to prevent filenames like ">xyz.jpg" (but well, you caught that in the -e $filename), e.g:

    unless( open( my $fh, '<', $cache ) ) { warn "Thumbnail.pm: $! opening $cache\n"; } else { local $/; binmode $fh; print <$fh>; };

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"