From ArchWiki
Jump to navigation Jump to search

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: If these formats are disabled for libmagick by default, shouldn't they also be disabled for graphicsmagick by default? (Discuss in Talk:ImageMagick#)

According to Wikipedia:

ImageMagick is a free and open-source software suite for displaying, converting, and editing raster image and vector image files. It can read and write over 200 image file formats.
Note: libmagick[broken link: replaced by imagemagick] uses Ghostscript for PDF, EPS, PS and XPS parsing. Because there have been multiple vulnerabilities with Ghostscript[1], these formats are now proactively disabled in /etc/ImageMagick-7/policy.xml with the following line:
<policy domain="coder" rights="none" pattern="{PS,PS2,PS3,EPS,PDF,XPS}" />
See also FS#59778.


Install the imagemagick package. Alternatively install graphicsmagick for GraphicsMagick, a fork of ImageMagick, emphasizing stability of the API and command-line interface.


See ImageMagick(1), or gm(1) for GraphicsMagick.

Popular operations include -append, -resize, -rotate, -quality and many more. For example, to combine multiple pictures into one:

$ convert -append input.pngs output.png
Note: The sign before an option is important. Opposite operations can be performed by using a plus instead of a minus.

To crop part of multiple images and convert them to another format:

$ mogrify -crop WIDTHxHEIGHT+X+Y -format jpg *.png

Where WIDTH and HEIGHT is the cropped output image size, and X and Y is the offset from the input image size.

Screenshot taking

An easy way to take a screenshot of your current system is using the import(1) command:

$ import -window root screenshot.jpg

import is part of the imagemagick package.

Running import without the -window option allows selecting a window or an arbitrary region interactively.

Note: If you prefer graphicsmagick alternative, just prepend "gm", e.g. $ gm import -window root screenshot.jpg.

Screenshot of multiple X screens

If you run twinview or dualhead, simply take the screenshot twice and use imagemagick to paste them together:

import -window root -display :0.0 -screen /tmp/0.png
import -window root -display :0.1 -screen /tmp/1.png
convert +append /tmp/0.png /tmp/1.png screenshot.png
rm /tmp/{0,1}.png

Screenshot of individual Xinerama heads

Xinerama-based multi-head setups have only one virtual screen. If the physical screens are different in height, you will find dead space in the screenshot. In this case, you may want to take screenshot of each physical screen individually. As long as Xinerama information is available from the X server, the following will work:

xdpyinfo -ext XINERAMA | sed '/^  head #/!d;s///' |
while IFS=' :x@,' read i w h x y; do
        import -window root -crop ${w}x$h+$x+$y head_$i.png

Screenshot of the active/focused window

The following script takes a screenshot of the currently focused window. It works with EWMH/NetWM compatible X Window Managers. To avoid overwriting previous screenshots, the current date is used as the filename.

activeWinLine=$(xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)")
import -window "$activeWinId" /tmp/$(date +%F_%H%M%S_%N).png

Alternatively, the following should work regardless of EWMH support:

$ import -window "$(xdotool getwindowfocus -f)" /tmp/$(date +%F_%H%M%S_%N).png
Note: If screenshots of some programs (dwb and zathura) appear blank, try appending -frame or removing -f from the xdotool command.


Error: # unsupported relocations with Radeon video card

Many users with Radeon video cards using opencl-mesa are receiving this error when trying to use ImageMagick to convert an image, whether directly or through another package using ImageMagick's API, i.e.: 1 2

$ convert source.png -resize '100x100' converted.jpg
Error: 8 unsupported relocations
Error: 8 unsupported relocations

Using opencl-amdAUR or intel-opencl-runtimeAUR is a temporary workaround. opencl-amdAUR is the proprietary AMD OpenCL implementation, which was able to be extracted from the proprietary AMDGPU PRO driver so that it runs on top of the open source AMDGPU. In this case, you may need to force OpenCL to select one of these alternatives, i.e.:

$ OCL_ICD_VENDORS=amdocl64 convert source.png -resize '100x100' converted.jpg

See also