Image Component – Resize Images

The following source code demonstrates how to resize an image to a specific width and height using the scalePixels() method.  You can also use scalePercent() to scale images to a specific percentage of the source image.

Source Code

<!— create the object —>
<cfset myImage = CreateObject(“Component”,“Image”) />

<!— open the image to resize —>
<cfset myImage.readImage(“d:\examples\fatherAndSon.jpg”) />

<!— resize the image to a specific width and height —>
<cfset myImage.scalePixels(100, 100) />

<!— output the image in JPG format —>
<cfset myImage.writeImage(“d:\examples\fatherAndSon-small.jpg”, “jpg”) />

<!— the new images —>
<p>
<b>fatherAndSon.jpg:</b><br>
<img src=“/examples/fatherAndSon.jpg”>
</p>
<p>
<b>fatherAndSon-small.jpg:</b><br>
<img src=“/examples/fatherAndSon-small.jpg”>
</p>

Results

AIC Example - Resize Images