Here is a bit of code I created using the new CFIMAGE tag in Coldfusion 8 to create thumbnails.
- When need to get the information on the “full size” Image. The image we want to create the thumbnail for. To do this : <cfimage action=”info” structname=”imagetemp” source=”The direct path to your image EX:c:\inetpup\wwwroot\photos\myimage.jpg”>
- Now that we have the information about the image, specifically the width and height we can begin the process of resizing. To do this <cfset x=min(150/imagetemp.width, 113/imagetemp.height) in this example the width of your thumbnail would never exceed 150 pixels and the height would not exceed 113 depend if the shot is horizontal or vertical. Of course you could adjust the 150 and 113 to suit your needs.
- You will 2 more cfsets to set the image size and finish the calculations.
<cfsest newwidth = x*imagetemp.width>
<cfset newheight = x*imagetemp.height>
- Finally lets write our thumbnail
<cfimage action=”resize” source=”again the path to the original image” width=”#newwidth#” height=”#newheight#” destination=”the place you would like to write the thumbnail file EX:C:\inetpub\wwwroot\photos\thumbnails\thumb_myimage.jpg”
Your final code will look something like this
<cfimage action="info" structname="imagetemp" source="Path to your image">
<cfset x=min(150/imagetemp.width, 113/imagetemp.height)>
<cfset newwidth = x*imagetemp.width>
<cfset newheight = x*imagetemp.height>
<cfimage action="resize" source="#Path to your image#" width="#newwidth#" height="#newheight#" destination="#thumbnail destination#">