Professional graphics and photo editing at the command line

Copyright and Co.

A little more complexity comes into play once you create custom shapes via ImageMagick's tools, mark images with a date or image credit, or add a watermark for online preview.

The command in Listing 5 adds a copyright label bottom left in the source image (SouthWest – note the capitalization of the cardinal directions). The font used here is 150-pixel-sized DejaVu Sans in white. The xy values that follow -annotate can be used to move the font pixel by pixel if necessary (e.g., +5+20). In the example, I left it at the original position ( ). The correct spelling of the installed fonts is provided by the command:

convert -list font

Listing 5

Label Images

$ convert image.jpg -gravity SouthWest -pointsize 150 -fill white \
  -font DejaVu-Sans -annotate 0 '(c) PHOTO FROM XYZ / 2022' target.jpg

To set a watermark, it's best to use ImageMagick's composite program to blend the source image with an existing image that has an alpha channel (i.e., a transparent background) (Figure 4). The value following -watermark can be between   (transparent) and 100 (fully opaque). The 50 in the example from Listing 6 means 50 percent opacity. The command, like all others with an asterisk instead of the filename, can be applied to all files of a certain type.

Listing 6

Watermark

$ composite -watermark 50 \
  -gravity Center \
  WATERMARK.png \
  SOURCE.jpg TARGET.jpg
Figure 4: Watermarks help you protect your images online.

Merging Images

You can use the assemble command to merge images into a single file. Some photographers use such images like this to capture folder contents at first glance. This can be very useful especially in the cloud or if bandwidth makes it difficult to preview images individually. The command from Listing 7 saves all PNG files of the current folder with a size of 800x600 pixels side by side in a JPEG and with defined spacing. In each case, the file name is inserted below the image (Figure 5).

Listing 7

Montage

$ montage -label %f \
  -geometry 800x600+10+10 \
  *.png imageindex.jpg
Figure 5: A labeled overview in an image helps you to save data volume in the cloud.

Conclusions

The features mentioned in this article only scratch the surface of ImageMagick's capabilities. The program has far more to offer, and detailed knowledge of it fills books. If you want to learn more about the extensive tool, the project homepage and the man pages of the individual tools are good places to start. The ImageMagick website also has a practical guide about drawing with the tool [2].

When working with the graphics toolbox, always bear in mind that learning a new tool will take some time. Even if you never quite master it or use it to create elaborate image compositions, ImageMagick is still a handy all-around tool in everyday life because of its batch options for converting formats, easy resizing, or embedding watermarks.

Infos

  1. ImageMagick: https://imagemagick.org
  2. Drawing with ImageMagick: https://imagemagick.org/Usage/draw/

The Author

Claudius Grieger discovered ImageMagick at the command line more or less by accident and has been using it ever since on his Debian system for batch conversion of graphics and photos.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News