imageCrop

Crops a ColdFusion image to a specified rectangular area.

imageCrop(name, x, y, width, height) → returns void

Member Function Syntax

someImage.crop(x, y, width, height)

Argument Reference

name string
Required

The image on which this operation is performed.

x numeric
Required

The X origin of the crop area.

y numeric
Required

The Y origin of the crop area.

width numeric
Required

The width of the crop area.

height numeric
Required

The height of the crop area.

Examples
Sample code invoking the imageCrop function

This example shows how to crop an image.

<!--- Create a ColdFusion image from an existing JPEG file. ---> 
 <cfimage source="../cfdocs/images/artgallery/lori05.jpg" name="myImage"> 
 <!--- Crop myImage to 100x100 pixels starting at the coordinates (10,10). ---> 
 <cfset imageCrop(myImage,10,10,100,100)> 
 <!--- Write the result to a file. ---> 
 <cfimage source="#myImage#" action="write" destination="test_myImage.jpg" overwrite="yes"> 
 <!--- Display the source image and the new image. ---> 
 <img src="../cfdocs/images/artgallery/lori05.jpg"/> 
 <img src="test_myImage.jpg"/>  

CF 11+ Lucee 4.5+ Crop the image from starting point (x=25, y=25), with width=100 and height=100

imgObj = imageRead("http://cfdocs.org/apple-touch-icon.png");
imgObj.crop(25,25,100,100);
cfimage(action="writeToBrowser", source=imgObj);

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub