Capturing Screenshots with ImageMagick

I know there’s no lack of free tools for capturing screenshots on GNU/Linux and BSD, but I recently discovered that if you’ve already got ImageMagick installed you don’t really need anything else. If you want to grab everything, it’s simple.

using import in the shell
$ import -window root site/images/busy-desktop.png

Actually, “-window root” isn't the simplest way to get capture the entire screen. That honor goes to this formula.

using import in the shell
$ import -screen site/images/single-window.png

However, knowing how to use the -window option is still handy even if you can’t be bothered to get a window’s ID, because a blank window ID will let you select a window with your pointer.

using import in the shell with a blank window ID
$ import -window '' site/images/imagemagick-import-single.png
a screenshot of a single window captured with ImageMagick
a screenshot of a single window captured with ImageMagick

I had that in the makefile I used to build and deploy this website at one point, but don’t bother now. Once I have the screenshot and have copied it to my site’s “images” directory, my makefile then generates a WEBP-formatted thumbnail so that I can show screenshots on my website without images taking an outrageously long time to load. I use the <picture> element to display WEBP for supported browsers.

using the HTML5 <picture> element
<figure>
  <a href="/images/busy-desktop.png" 
     title="click for full-size view">
    <picture>
      <source srcset="/images/busy-desktop.webp" 
	      type="image/webp">
      <source srcset="/images/busy-desktop.png" 
	      type="image/jpeg"> 
      <img src="/images/busy-desktop.png" 
	   alt="a screenshot of my desktop with windows open" 
	   width="360"
	   loading="lazy">
    </picture>
  </a>
  <figcaption>
    a screenshot of my desktop with windows open
  </figcaption>
</figure>

IE11 gets full-sized PNG and JPG images since it doesn’t support WEBP, but this is my personal website so I don’t give a damn. IMO, the only people still using IE11 work for the government and they shouldn’t be visiting my website on the job.