This is my first bit of programming in quite a while, so I'm basically starting from scratch, and I'm using coldfusion 8.
What I'm trying to do is create a series of uniform thumbnail images (always 68 X 46) from a variety of larger images, some portrait, some landscape. In both cases resizing the image to fill the height or width of the thumbnail and then cropping the excess image equally off either side (top/bottom, left/right). Just as photoshop does by default with canvas resize.
The code below works really well as long as the source images dimensions/ratio is perfect, but I've started to run into cases where the code fails. In this case, when a resized images width ends up being less than 68.
<cfif FileExists(ExpandPath('images/gallery/thumbs/thm_'&imageMed[i].medium.XmlText)) IS false> <!--- If the thumb doesn't exist, create it. --->
<cfif imageDataThumb.width gt imageDataThumb.height >
<!--- Landscape --->
<cfset ImageResize(cfImageThumb,"","46")>
<cfset ImageCrop(cfImageThumb,(cfImageThumb.width-68)/2,0,68,46)> <!--- Crop left/right edges of images --->
<cfimage source="#cfImageThumb#" action="write" destination="images/gallery/thumbs/thm_#imageMed[i].medium.XmlText#" overwrite="yes">
<cfelse>
<!--- Portrait --->
<cfset ImageResize(cfImageThumb,"68","")>
<cfset ImageCrop(cfImageThumb,0,(cfImageThumb.height-23)/2,68,46)>
<!--- Crop top/bottom edges of images --->
<cfimage source="#cfImageThumb#" action="write" destination="images/gallery/thumbs/thm_#imageMed[i].medium.XmlText#" overwrite="yes">
</cfif>
Trying to solve these "edge cases" is turning the code into a mess. Is there a better way to approach this? Something in coldfusion or a cfc?