I have a page with a gallery of 150px x 180px thumbnails. People are allowed to
upload their own photos, and the vast majority of them are not the exact same
aspect ratio. I want their photo, regardless of orientation or size, to end up
with a maximum width of 150px or a maximum height of 180px.
I currently have code that does this (shown below) but I figure there's
probably an easier way. We just upgraded to CF8 this week, so I'm a bit behind
the curve on the new tags. Any ideas on a better way to go about this? Thanks!
My current code:
<!--- First, we save the image. --->
<cffile action="upload" filefield="Image1" MODE="777" destination="#txtPath#"
nameconflict="makeunique" result="CharacterImage" />
<!--- Then we convert the image to a jpg if it's not already --->
<cfif #CharacterImage.serverFileExt# NEQ "jpg">
<cfimage source="#txtPath##CharacterImage.serverFile#" action="convert"
destination="#CharacterImage.serverFile#.jpg">
</cfif>
<cfset baseImage = "#CharacterImage.serverFile#">
<!--- Now we get the image information --->
<cfimage action = "info" source = "#txtPath##baseImage#" structname =
"imageinfo">
<!--- check to see if it needs to fit within the width or height --->
<cfset x = 150/imageinfo.width>
<cfset y = 180/imageinfo.height>
<!--- and resize accordingly --->
<cfif y LTE x>
<cfset widthpercentage = y * 100>
<cfimage action="resize" source = "charImages\#baseImage#" height="180"
width = "#widthpercentage#%" destination = "charImages\#baseImage#" overwrite
= "yes">
<cfelse>
<cfset heightpercentage = x * 100>
<cfimage action="resize" source = "charImages\#baseImage#"
height="#heightpercentage#%" width = "150" destination =
"charImages\#baseImage#" overwrite = "yes">
</cfif>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know
on the House of Fusion mailing lists
Archive:
http://www.houseoffusion.com/groups/cf-newbie/message.cfm/messageid:4570
Subscription: http://www.houseoffusion.com/groups/cf-newbie/subscribe.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.15