imageClearRect

Clears the specified rectangle by filling it with the background color of the current drawing surface.

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

Member Function Syntax

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

Argument Reference

name string
Required

The image on which this operation is performed

x numeric
Required

The X coordinate of the rectangle to clear.

y numeric
Required

The Y coordinate of the rectangle to clear.

width numeric
Required

The width of the rectangle to clear.

height numeric
Required

The height of the rectangle to clear.

Examples
Sample code invoking the imageClearRect function

This example shows how to set the background color to green and draws four rectangles in that color on the image.

<!--- Create a ColdFusion image from an existing JPEG file. ---> 
 <cfimage source="../cfdocs/images/artgallery/jeff05.jpg" name="myImage"> 
 <!--- Set the background color to green. ---> 
 <cfset imageSetBackgroundColor(myImage,"green")> 
 <!--- Draw four rectangles in the background color. ---> 
 <cfset imageClearRect(myImage,10,25,50,50)> 
 <cfset imageClearRect(myImage,100,25,50,50)> 
 <cfset imageClearRect(myImage,10,100,50,50)> 
 <cfset imageClearRect(myImage,100,100,50,50)> 
 <!--- Save the modified ColdFusion image to a file. ---> 
 <cfimage source="#myImage#" action="write" destination="test_myImage.jpeg" overwrite="yes"> 
 <!--- Display the source image and the new image. ---> 
 <img src="../cfdocs/images/artgallery/jeff05.jpg"/> 
 <img src="test_myImage.jpeg"/> 

CF 11+ Lucee 4.5+ Clears the specified rectangle (50x50) from the center of the image (x=50, y-50)

imgObj = imageRead("http://cfdocs.org/apple-touch-icon.png");
imgObj.clearRect(50,50,50,50);
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