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
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
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
- ImageMagick: https://imagemagick.org
- Drawing with ImageMagick: https://imagemagick.org/Usage/draw/
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.