Ubuntu – ImageMagick: identify fails to identify XWD images


My goal is to be able to take a screenshot of all menus, regardless of tooltip or X window grabbing pull down menus, including the sprocket menu in Ubuntu, e.g., like this, and annotate them in another drawing tool such as Shutter:


And the way I do this outside of Shutter (because it actually will not grab that menu, even though it is advertising that it does), is use xwd to grab the whole root window, convert it to a PNG file, load it into Shutter and then crop it down. Very time-wasting effort to do this, but it has been working so far until recently.

On Ubuntu:

drunkard@norehab:~$ lsb_release -r -i
Distributor ID: Ubuntu
Release:    17.04

I take a full screenshot using xwd:

drunkard@norehab:~$ xwd -root -out /tmp/xwd.tmp.6821
drunkard@norehab:~$ file /tmp/xwd.tmp.6821
/tmp/xwd.tmp.6821: XWD X Window Dump image data, "xwdump", 3840x1215x24

I encountered the error during conversion from XWD to PNG format:

drunkard@norehab:~$ convert /tmp/xwd.tmp.6821 /home/drunkard/screenshot.2017-10-07.08-13-55.PDT.png
convert-im6.q16: no decode delegate for this image format `6821' @ error/constitute.c/ReadImage/504.
convert-im6.q16: no images defined `/home/drunkard/screenshot.2017-10-07.08-13-55.PDT.png' @ error/convert.c/ConvertImageCommand/3258.

I have this version of identify:

drunkard@norehab:~$ file /usr/bin/identify
/usr/bin/identify: symbolic link to /etc/alternatives/identify
drunkard@norehab:~$ readlink -f /etc/alternatives/identify
drunkard@norehab:~$ apt-file search /usr/bin/identify-im6.q16
imagemagick-6.q16: /usr/bin/identify-im6.q16
imagemagick-6.q16hdri: /usr/bin/identify-im6.q16hdri
drunkard@norehab:~$ dpkg --listfiles imagemagick-6.q16 | grep identify
drunkard@norehab:~$ apt-cache --no-all-versions show imagemagick-6.q16 
Package: imagemagick-6.q16
Architecture: amd64
Version: 8:
Multi-Arch: foreign
Priority: optional
Section: graphics
Source: imagemagick
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: ImageMagick Packaging Team <pkg-gmagick-im-team@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 644
Provides: imagemagick, imagemagick-6.defaultquantum
Depends: libc6 (>= 2.4), libmagickcore-6.q16-3 (>= 8:, libmagickwand-6.q16-3 (>= 8:, hicolor-icon-theme
Recommends: libmagickcore-6.q16-3-extra, ghostscript, netpbm
Suggests: imagemagick-doc, autotrace, cups-bsd | lpr | lprng, curl, enscript, ffmpeg, gimp, gnuplot, grads, graphviz, groff-base, hp2xx, html2ps, libwmf-bin, mplayer, povray, radiance, sane-utils, texlive-base-bin, transfig, ufraw-batch, xdg-utils
Breaks: libmagickcore-dev (<< 8:
Replaces: imagemagick (<< 8:
Filename: pool/main/i/imagemagick/imagemagick-6.q16_6.9.7.4+dfsg-3ubuntu1.2_amd64.deb
Size: 423848
MD5sum: 6f06b63767fb5e32d967e4395d4e4f98
SHA1: ba0b8af93fed0e9d1efabe56e79387f1bc4944e5
SHA256: 84ffd5f3eb1c8bdc11955c581fc98f1c1bb37eb40609ef6997c8675f1dfd29d0
Homepage: http://www.imagemagick.org/
Description-en: image manipulation programs -- quantum depth Q16
 ImageMagick is a software suite to create, edit, and compose bitmap images.
 It can read, convert and write images in a variety of formats (over 100)
 including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript,
 SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale,
 shear and transform images, adjust image colors, apply various special
 effects, or draw text, lines, polygons, ellipses and B├ęzier curves.
 All manipulations can be achieved through shell commands as well as through
 an X11 graphical interface (display).
 For working with the SVG, WMF, OpenEXR, DjVu and Graphviz formats,
 you need to install the libmagickcore-6.q16-3-extra package.
 This version of imagemagick is compiled for a channel
 depth of 16 bits (Q16).
Description-md5: e40daf0bbbffd2b9ac49e04c8c3480fe
Task: ubuntu-desktop, ubuntu-usb, print-server, kubuntu-desktop, edubuntu-desktop, edubuntu-usb, xubuntu-core, xubuntu-desktop, mythbuntu-desktop, lubuntu-desktop-share, lubuntu-gtk-desktop, lubuntu-desktop, lubuntu-qt-desktop, ubuntustudio-desktop-core, ubuntustudio-desktop, ubuntu-gnome-desktop, ubuntukylin-desktop, ubuntu-mate-core, ubuntu-mate-desktop, ubuntu-budgie-desktop
Supported: 9m

N: There is 1 additional record. Please use the '-a' switch to see it

But identify can't identify it:

drunkard@norehab:~$ identify /tmp/xwd.tmp.6821
identify-im6.q16: no decode delegate for this image format `6821' @ error/constitute.c/ReadImage/504.

This used to work.

Best Answer

An easy way to get around this possible limitation of imagemagick is to slightly alter your technique for grabbing a screenshot. Instead of using your current 2 step technique:

  1. Grab the screenshot with xwd
  2. Convert with imagemagick

use a 'pipe' to make the process a single command:

xwd -root | convert xwd:- test.png

This worked beautifully on my system and will get around the issue you have experienced. A screenshot of myself typing up this answer (cropped a little post screenshot) using this technique:

enter image description here

There are many more ideas for utilising xwd for this purpose in the references below...