webCOMAND

#IMAGE Draw

Draw a point, line or shape on an existing image.

Only supported by ImageMagick image processing engine.

Prototype

#IMAGE($image_bytes, 'Draw', $method, $coords, $stroke_width, $stroke_color, $fill_color = 'transparent')

Parameters

  • method - One of the following options.
    • Point - Draw a point (pixel) where coords are: x, y (stroke_width and fill_color ignored)
    • Line - Draw a line where coords are: x1, y1, x2, y2
    • Rectangle - Draw a rectangle where coords are: x1, y1, x2, y2
    • RoundRectangle - Draw a rectangle with rounded corners where coords are: x1, y1, x2, y2, x_radius, y_radius
    • Circle - Draw a circle where coords are: cx, cy, x1, y1 where cx, cy specifies the center and x1, y1 specifies a point on the circle.  To specify a radius, set x1 to the radius and y1 to y.
    • Arc - Draw an arc where coords are: x1, y1, x2, y2, start_degrees (0-360), end_degrees (0-360)
    • Ellipse - Draw an ellipse where coords are: cx, cy, x2, y2, start_degrees (0-360), end_degrees (0-360)
    • Polyline - Draw a sequence of lines where coords are repeated: x, y
    • Polygon - Draw an enclosed sequence of lines the last x, y will connect to the first x, y and where coords are repeated: x, y
    • Bezier - Draw a bezier curve based on a sequence of points where coords are repeated: x, y.  The first and last points anchor the curve, and the in-between points "pull" the curve toward those points along the way from the first to the last.
  • coords - An array or string containing a sequence of numbers (integers or decimals) unique to each method described above.  Each number may be separated by a comma and/or spaces.
  • stroke_width - Width of the line(s) drawn.
  • stroke_color - Color of the point or line(s) drawn.
  • fill_color - Color of the area between the lines drawn.

Example

#/ get logo image width, height and center.
#NEW($img)#IMAGE('',New,320,200,white)#ENDNEW
#NEW($w)#IMAGE($img,GetWidth)#ENDNEW
#NEW($h)#IMAGE($img,GetHeight)#ENDNEW
#LOCAL($cx,$w / 2)
#LOCAL($cy,$h / 2)
#LOCAL($qx,$w / 4)
#LOCAL($qy,$h / 4)
#LOCAL($tx,$w * 3 / 4)
#LOCAL($ty,$h * 3 / 4)

#/ draw two lines dividing the image into four quadrants
#NEW($img)#IMAGE($img,Draw,Line,'$cx,0, $cx,$h',1,blue)#ENDNEW
#NEW($img)#IMAGE($img,Draw,Line,[0,$cy, $w,$cy],1,blue)#ENDNEW

#/ draw a magenta point in the center of the image
#NEW($img)#IMAGE($img,Draw,Point,'$cx,$cy',0,white)#ENDNEW

#/ draw a green rectangle around the border
#NEW($img)#IMAGE($img,Draw,Rectangle,'0,0 $w,$h',4,green)#ENDNEW
#NEW($img)#IMAGE($img,Draw,RoundRectangle,'$qx,$qy $cx,$cy 8,4',2,red)#ENDNEW

#/ draw a circle, arc and ellipse
#NEW($img)#IMAGE($img,Draw,Circle,'$cx,$cy $cx,0',2,orange)#ENDNEW
#NEW($img)#IMAGE($img,Draw,Arc,'$qx,$qy $tx,$ty 270,360',2,black)#ENDNEW
#NEW($img)#IMAGE($img,Draw,Ellipse,'$cx,$cy $qx,$qy 0,270',2,pink)#ENDNEW

#/ draw a polyline, filled polygon and bezier curve
#NEW($img)#IMAGE($img,Draw,Polyline,'$tx,$qy $tx,$ty $qx,$ty',2,cyan)#ENDNEW
#NEW($img)#IMAGE($img,Draw,Polygon,'$tx,$ty $w,$ty $w,$h',2,red,plum)#ENDNEW
#NEW($img)#IMAGE($img,Draw,Bezier,'$tx,$ty $w,$ty $w,$h',2,gold)#ENDNEW

#RETURN($img)