In this episode you'll draw shapes and lines with -draw, write text with -annotate, create transparent watermarks, and use caption for text that automatically adjusts its size.

In episode 6 you arranged many images into a thumbnail grid with magick montage. This time we're reversing direction: instead of combining existing images, you'll draw directly onto a blank canvas — geometric shapes, lines, up to text. This capability sounds like graphics-editor work, but ImageMagick does it through command text, so it can be used in automated pipelines: adding labels to thousands of photos, inserting watermarks into certificates, or creating banners for campaigns.
The key concept is simple: each command draws one layer on top of the image, and the order of commands determines which layer appears in front. That's how we build image compositions without opening them one by one.
Before drawing, we need a canvas. ImageMagick has the xc: pseudo-format that creates a plain image filled with a single color:
magick -size 800x600 xc:white canvas.png-size 800x600 sets the canvas dimensions, and xc:white fills it with white. This is the equivalent of opening a blank document in a graphics editor. Any color works — xc:transparent produces a transparent canvas, useful when the result will be combined with other images.
-drawThe core of drawing in ImageMagick is -draw, which accepts a string containing one or more primitives. Each primitive uses the pixel coordinate system: x,y with 0,0 at the top-left corner.
magick -size 800x600 xc:white \
-stroke black -fill '#e74c3c' -strokewidth 3 \
-draw "rectangle 50,50 250,250" \
-draw "circle 400,200 400,120" \
-draw "polygon 500,400 650,300 700,450" \
-draw "line 20,500 780,500" \
shapes.pngNote the coordinate patterns of each primitive:
rectangle x1,y1 x2,y2 — two opposite corners, forming a rectangle.circle cx,cy px,py — the center point then one point on the circumference; the distance between them becomes the radius.polygon — a list of points connected and closed automatically.line x1,y1 x2,y2 — two points connected by a straight line.The description of each primitive is the same language ImageMagick uses, so once you memorize the basic shapes, you can easily read and write other people's commands.
For curved lines, the bezier primitive uses four points on a cubic curve — analogous to the pen tool in vector editors.
magick -size 400x300 xc:white \
-stroke '#2e86de' -fill none -strokewidth 2 \
-draw "bezier 20,250 100,50 300,50 380,250" \
bezier.pngFour consecutive points define the curve: the start point, two control points that "pull" the curve's direction, and the end point. -fill none makes the curve unfilled — only the line is visible. The combination of bezier and polygon is enough to draw simple logos and icons from the command line.
The two options most often paired with -draw:
-stroke Color — the edge line color; supported by -strokewidth for thickness.-fill Color — the fill color inside the shape. Colors can be hex (#e74c3c) or other formats from episode 3.The difference is easy to guess: fill fills the inside of the shape, stroke draws its edge. When both are used, the shape looks "framed". When only -stroke is used without -fill (or with -fill none), only the outline remains — a favorite technique for diagrams.
-annotateText is written with -annotate, combined with three main options: -font for the typeface, -pointsize for the size, and -gravity for the anchor position.
magick canvas.png \
-font DejaVu-Sans -pointsize 48 -fill '#333333' \
-gravity South -annotate 0x0+0+40 "Rilis 2026" \
annotated.png-gravity South anchors the text to the bottom edge, and 0x0+0+40 adds an offset of 40 pixels from that edge. The first number of -annotate is the rotation in degrees — -annotate 15x15+0+40 tilts the text 15 degrees. The combination of gravity and offset is the most convenient way to place text without manually computing coordinates.
Tip
To see the fonts available on your system, run magick -list font. The names that appear in the family column can be used directly as the -font value, for example DejaVu-Sans-Bold or Liberation-Serif. A system without DejaVu fonts will reject that name, so check first.
A watermark is text placed on top of an image with low opacity. In episode 5 you learned about alpha; now we use it in practice: a rgba(...) fill with an alpha value below 1 makes the text see-through.
magick foto.jpg \
-font DejaVu-Sans-Bold -pointsize 64 \
-fill 'rgba(255,255,255,0.35)' -gravity SouthEast \
-annotate +20+20 "devvnull" \
foto-watermark.jpgrgba(255,255,255,0.35) means white with 35 percent opacity. Because -annotate draws on top of the existing image, the original photo stays intact underneath. The same pattern is used to add serial numbers, dates, or owner names to thousands of files at once — that's why CLI watermarks are so popular for digital assets.
caption:What if the text is long and must fit the canvas size? Writing long text with -annotate risks spilling past the image edge. The solution is the caption: pseudo-format: ImageMagick wraps the text lines automatically so they fit within the given -size.
magick -size 600x200 -background white -gravity center \
caption:'Rilis utama 2026 sudah tersedia untuk semua pengguna.' \
caption.pngcaption: reads the text, measures its length, then either reduces the font size or wraps lines so the entire text is contained. This is very useful for dynamic labels whose length is never the same — for example notifications from the latest data. Unlike -annotate, which always uses the size you specify, caption: adapts to the content.
In episode 7 you've drawn shapes with -draw — rectangle, circle, polygon, line, and bezier — controlled the edge and fill via -stroke and -fill, written text with -annotate along with -font, -pointsize, and -gravity, created transparent watermarks with rgba fills, and used caption: for text that automatically adjusts its size.
The takeaway: an image is a canvas, and command order is layering. All of these skills are building blocks for creating more complex images, such as banners and cards, entirely from the command line.
In the next episode 8 we change the image's mood: filters and effects — blur, sharpen, edge detection, up to artistic effects like charcoal and wave. See you then!