Yeah, yeah, I know. There are already a billion and 3 CSS showcase galleries out there. Why re-invent the wheel, you surely say?

Well, I'm actually not…well, not really. I have a few projects that are hovering on the horizon for which I am going to be using a few features I've never built before, such as a rating system, and a tagging system. While I feel confident that they will be no big deal, I figure something like this could provide a good playground for working those things out now, rather than later.

One thing I am going to do with my CSS gallery, however, is auto-generated thumbnails. I really want to do nothing but approve or deny submissions, so the thought of taking time to open the RAM-whore Photoshop CS3 to crop up a bunch of images is not appealing!

In thinking about this, I snooped around the Intrablog for some free services that would provide this. One of them, Websnapr, has an extremely easy to use API…the only problem is that they slap a stupid watermark on the thumbnails that are generated. So obviously, I moved on. The next one I found (and stuck with, incidentally), was Their web service is pretty easy too, although quite poorly documented (urgghh…). And as a bonus, they do not force a watermark on the image that is generated, they store the files generated on their servers, and they allow up to something like 250,000 requests per month–not bad at all!

So, to drag this post out just a bit longer, I wrote some ColdFusion that will take care of the thumbnail creation for me, and it is as follows:

<cfhttp url="" method="get">
    <cfhttpparam name="Service" value="ShrinkWebUrlThumbnail" type="url">
    <cfhttpparam name="Action" value="Thumbnail" type="url">
    <cfhttpparam name="STWAccessKeyId" value="107c0d4c8c1e64f" type="url">
    <!---<cfhttpparam name="Size" value="lg" type="url">--->
    <cfhttpparam name="u" value="bb1b1" type="url">
    <cfhttpparam name="xmax" value="275" type="url">
    <cfhttpparam name="ymax" value="207" type="url">
    <cfhttpparam name="Url" value="" type="url">

This is a pretty simple HTTP GET operation. This service requires an obnoxious number of parameters, but they're easy enough to figure out. One note: You can either use the default size options ("sm" and "lg"), or you can use the "xmax" and "ymax" parameters to specify your own custom size. However, you cannot use all three together.

And finally, the response:

<cfset thumbXMLStruct = #xmlParse(cfhttp.FileContent)#>
<cfset rawThumb = #thumbXMLStruct.ThumbnailResponse.Response.ThumbnailResult.Thumbnail.xmltext#>
<cfset removehttp = replace(rawThumb, 'http://', '', 'all')>
<cfset newThumb = replace(removehttp, '/', '_', 'all')>
<cfimage action="write" destination="#expandPath('thumbs/#newThumb#')#" source="#rawthumb#" overwrite="yes">
<cfimage action="writetobrowser" source="#rawThumb#"> 

The GET returns an XML structure; I parse it, grab the returned URL, and give it to cfimage to write the image to the file system (and later, its path to the database).

So yeah, this is pretty simple and ugly. The resulting name of the file is awful and needs to be addressed, but I'm feeling too lazy this evening to bother. Right now this works, so really half of the CSS gallery is done from a management perspective–woot!