Create Image Thumbnail in Coldfusion without losing dimension ratio.

This is simple application to create image thumbnail in ratio using coldfusion.


<!--- 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>
view raw uploadfile.cfm hosted with ❤ by GitHub


I think this is useful for new coldfusion programmers.

Comments

Popular posts from this blog

Login with facebook using coldfusion

Create CSV file in Coldfusion Using CFFile

Get Previous One Day Data in Sql Server