Finding Wide Images with CF8's Image Functions

Tags | ColdFusion | Libraries

Posted on November 6, 2009 by Daria

Ok, so I know I’m a little behind the curve, but I’ve finally been given free reign to use ColdFusion 8 specific tags and functions at work. Issues with a major application during the first testing caused the upgrade to be delayed by 10 months. We finally have an upgraded date so I can start thinking in CF8 instead of CF7. Woot! I was so excited by the first problem I solved that I thought I’d share it.

Problem: The Free Library of Philadelphia has an ever growing Digital Collections database of digitized items from their Rare Books and Print and Picture Departments. Currently I am preparing a new collection of almost 4000 images from the Maps Collection. The images will be zoomable and some will even be geolocated and fit into a mosaic with current Google map street overlays. We use a batch conversion tool to create the web ready images and thumbnails to display in the search results. The problem is the first few batches were converted with incorrect settings and some of the images are too wide for the site. Unfortunately I discovered this after converting the rest of the collection so I needed a way to find only the ones that need to be redone.

Solution: Use the new CF8 image functions to find the width of all the images and list the ones that are too wide. Here is the whole script. It took me only an hour to find the 862 that need to be redone.

	mapImagePath = '/images/maps/';
	mapFullPath = expandPath(mapImagePath);

<cfdirectory directory="#mapFullPath#"
	recurse="yes" />

	for (x=1; x lte test.recordCount; x++) {
		currImage = imageNew('[x]#\[x]#');
		currImageWidth = imageGetWidth(currImage);
		if (currImageWidth > 512) {
			writeOutput('[x]# (#currImageWidth#)<br>');

Now if only that code could be completely in cfscript… Off to dream about CF9.