Not yet rated

Problem

Ever needed to resize images on the fly? Its easy with ColdFusion and cfimage.

Solution

I have 3 images 1-3.jpg in a directory Read the image into memory. Write the image at the current size to the browser. Resize the image in memory. At this stage you could write the image back to a file or attach it to an email via cfmail etc. Write the small image to the browser.

Detailed explanation


<cfloop from=
"1" to=
"3" index=
"i">  
         
<!---
Read in the file --->  
         
<cfimage action=
"read" source=
"#expandPath('.')#\#i#.jpg" 
 name=
"tempPicture" />  
         
<!---
output the original image --->  
         
<cfimage action=
"writetobrowser" source=
"#tempPicture#" />

         
         
<!---
resize the image --->  
         
<cfimage action=
"resize" width=
"30%" height=
"30%"     source=
"#tempPicture#" name=
"smallPicture" /> 

         
<!---
write small image to browser --->  
         
<cfimage action=
"writetobrowser" source=
"#smallPicture#"/>
 
 
</cfloop>
  
  

 

Yes thats all thats required.


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes