Draws a rectangle.

imageDrawRect(name, x, y, width, height [, filled]) → returns void

Member Function Syntax

someImage.drawRect(x, y, width, height [, filled])

Argument Reference for the imageDrawRect function


Required: Yes
The image on which this operation is performed.


Required: Yes
The x coordinate of the rectangle.


Required: Yes
The y coordinate of the rectangle.


Required: Yes
The width of the rectangle.


Required: Yes
The height of the rectangle.


Required: No
Default: false
Specify whether the rectangle is filled

Examples sample code invoking the imageDrawRect function

Tag Syntax

This example shows how to draw a rectangle.

<!--- Use the imageNew function to create a ColdFusion image that is 150 pixels wide and 200 pixels high. ---> 
 <cfset myImage=imageNew("",150,200)> 
 <!--- Set the drawing color for the image to yellow. ---> 
 <cfset imageSetDrawingColor(myImage,"yellow")> 
 <!--- Turn on antialiasing to improve image quality. ---> 
 <cfset imageSetAntialiasing(myImage,"on")> 
 <!--- Draw a filled yellow rectangle on the image. ---> 
 <cfset imageDrawRect(myImage,25,45,100,20,"yes")> 
 <!--- Display the image in a browser. ---> 
 <cfimage source="#myImage#" action="writeToBrowser"> 

Using drawRect member function

CF 11+ Lucee 4.5+ Create an new image. With the new image draw filled rectangle (width=70, height=50) starting at point (x=40,y=50)

imgObj = imageNew("",152,152,"rgb","149c82");
cfimage (action="writeToBrowser", source=imgObj);

Fork me on GitHub