Create Image Thumbnail in Coldfusion without losing dimension ratio.
This is simple application to create image thumbnail in ratio using coldfusion.
I think this is useful for new coldfusion programmers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- Upload file. ---> | |
<cfset UploadPath="x:\abc\uploads"> | |
<cfset ThumbnailHeight="200"> | |
<cfset ThumbnailWidth="200"> | |
<!---Logofile is the name of form fields---> | |
<cffile action="upload" filefield="#Logofile#" destination="#UploadPath#" nameconflict="MakeUnique"> | |
<cfset LogoFile = #File.ServerFile#> | |
<cfset SourcePic = UploadPath & "/" & LogoFile> | |
<cfimage action="info" structname="imagetemp" source="#SourcePic#"> | |
<cfset x=max(imagetemp.width,imagetemp.height)> | |
<cfset newheight=imagetemp.height*ThumbnailHeight/x> | |
<cfset newwidth=imagetemp.width*ThumbnailWidth/x> | |
<cfimage action="resize" source="#UploadPath#/#LogoFile#" width="#newwidth#" height="#newheight#" destination="#UploadPath#/t_#LogoFile#" overwrite="true"> | |
<!---This is another way to create image thumbnail without losing dimension ratio.---> | |
<cffile action="upload" filefield="#Logofile#" destination="#UploadPath#" nameconflict="MakeUnique"> | |
<cfset LogoFile = #File.ServerFile#> | |
<cfset SourcePic = UploadPath & "/" & LogoFile> | |
<cfimage source="#SourcePic#" name="SourceImage"> | |
<cfset info=ImageInfo(SourceImage)> | |
<cfif Info.Width GE Info.Height> | |
<cfimage source="#SourcePic#" action="resize" width="219" height="" destination="#UploadPath#/t_#LogoFile#" overwrite="No"> | |
<cfelse> | |
<cfimage source="#SourcePic#" action="resize" width="" height="234" destination="#UploadPath#/t_#LogoFile#" overwrite="No"> | |
</cfif> |
I think this is useful for new coldfusion programmers.
Comments
Post a Comment