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 for the imageClearRect function


Required: Yes
The image on which this operation is performed


Required: Yes
The X coordinate of the rectangle to clear.


Required: Yes
The Y coordinate of the rectangle to clear.


Required: Yes
The width of the rectangle to clear.


Required: Yes
The height of the rectangle to clear.

Examples sample code invoking the imageClearRect function

Tag Syntax

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"/> 

Using clearRect member function

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

imgObj = imageRead("");
cfimage(action="writeToBrowser", source=imgObj);

Fork me on GitHub