Use <CFIMAGE> to Generate Temporary Thumbnails

Social Share Toolbar

I’m wrapping up a sizable project that required 200×200 thumbnails for about two thousand pieces of content. The agency I’m working with required properly-sized thumbnails to proceed with their testing. Unfortunately, thumbnails did not exist at that point.

ColdFusion <CFIMAGE> to the rescue!

By using <CFIMAGE>, I was able to generate thumbnails for every piece of content in under 30 seconds. To add a little variety into the mix I created five different base images named thumb1.jpg – thumb5.jpg and chose one at random for each record. As I looped through the table that contained the content records, I used the content record’s ID (an auto-generated integer) as the filename and updated the thumbnail field as I went along.

The code I used looks something like this:

	select *
	from content



		UPDATE	content
		SET	thumbnail_image=''
		WHERE	contentID = '#contentID#'

The “cfset imageDrawText” line is the one that adds the text contained in the content_name column to the image. It also places the caption 5px in and 15px down from the top left corner of the image.

When the code finishes I have unique thumbnails for each piece of content.