The ImagickDraw class helps you create vector images with ImageMagick. These
vector images can be saved as files.
Syntax:
bool ImagickDraw::s()
Example:
Here's an example of how to use the ImagickDraw::point() function in PHP:
<?php
// Create an ImagickDraw object
$draw = new \ImagickDraw();
// Set the filled color
$draw->setFillColor('red');
// Use loop to draw 10000 points in given area
for ($x = 0; $x < 10000; $x++) {
$draw->point(rand(0, 300), rand(0, 300));
}
// Create an Imagick object
$imagick = new \Imagick();
// Set the new image size
$imagick->newImage(300, 300, 'white');
// Set the image format
$imagick->setImageFormat("png");
// Function to draw the image
$imagick->drawImage($draw);
header("Content-Type: image/png");
// Display the output image
echo $imagick->getImageBlob();
?>
Output:
This script generates a 300x300 PNG image filled with 10,000 red points.
The list of complete ImagickDraw functions are given below:
| ImagickDraw Functions | Description |
|---|---|
| ImagickDraw::annotation() | Draw text on the image. |
| ImagickDraw::arc() | Draw an arc. |
| ImagickDraw::bezier() | Draw bezier curves. |
| ImagickDraw::circle() | Draw a circle. |
| ImagickDraw::getStrokeOpacity() | Return the opacity of the outlines of stroked objects. |
| ImagickDraw::getStrokeWidth() | Return the width of the stroke used to draw object outlines. |
| ImagickDraw::line() | Draw a line. |
| ImagickDraw::point() | Draw a point. |
| ImagickDraw::polygon() | Draw a polygon using an array of coordinates. |
| ImagickDraw::polyline() | Draw a polyline using the current stroke settings and an array of coordinates. |
| ImagickDraw::rectangle() | Draw a rectangle. |
| ImagickDraw::rotate() | Rotate the current coordinate space by a specified angle. |
| ImagickDraw::roundRectangle() | Draw a rounded rectangle. |
| ImagickDraw::scale() | Adjust the scaling factor applied to the current coordinate space in horizontal and vertical directions. |
| ImagickDraw::setFillColor() | Set the color to be used for filling shapes. |
| ImagickDraw::setFillOpacity() | Set the opacity to use when drawing using the fill color or texture. |
| ImagickDraw::setFont() | Set the fully-specified font to use when annotating with text. |
| ImagickDraw::setFontFamily() | Set the font family to use when annotating with text. |
| ImagickDraw::setFontSize() | Set the font size in points to use when annotating text. |
| ImagickDraw::setFontStyle() | Set the font style to use when annotating with text (e.g., normal, italic, bold). |
| ImagickDraw::setFontWeight() | Set the font weight to use when annotating with text (e.g., normal, bold). |
| ImagickDraw::setGravity() | Set the placement gravity for text annotations (left, center, right). |
| ImagickDraw::setStrokeAlpha() | Specify the opacity of stroked object outlines (0.0 to 1.0). |
| ImagickDraw::setStrokeColor() | Set the color used for stroking object outlines. |
| ImagickDraw::setStrokeLineJoin() | Define how the corners of paths are joined when they are stroked (round, bevel, miter). |
| ImagickDraw::setStrokeMiterLimit() | Specify the miter limit of the stroke. A higher limit defines sharper corners. |
| ImagickDraw::setStrokeOpacity() | Set the opacity of stroked object outlines (0.0 to 1.0). |
| ImagickDraw::setStrokeWidth() | Set the width of the stroke used to draw object outlines. |
| ImagickDraw::setTextAlignment() | Specify the text alignment for annotations (left, center, right). |
| ImagickDraw::setTextAntialias() | Control whether the text is antialiased (smoothed) or not (jagged edges). Text is antialiased by default. |
| ImagickDraw::setTextDecoration() | Set the decoration to be applied to text annotations (underline, overline, none). |
| ImagickDraw::setTextUnderColor() | Set the color of a background rectangle to be placed under text annotations. |
| ImagickDraw::setViewbox() | Set the overall canvas size for drawing operations. |
| ImagickDraw::skewX() | Skew the current coordinate system in the horizontal direction. |
| ImagickDraw::skewY() | Skew the current coordinate system in the vertical direction. |
| ImagickDraw::translate() | Apply a translation (shift) to the current coordinate system. |
