{"id":14434,"date":"2026-07-20T02:00:00","date_gmt":"2026-07-20T06:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=14434"},"modified":"2026-07-13T17:09:08","modified_gmt":"2026-07-13T21:09:08","slug":"resize-images-at-the-command-line","status":"publish","type":"post","link":"http:\/\/www.both.org\/?p=14434","title":{"rendered":"Resize images at the command line"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"14434\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">1    <\/span>\r\n<\/div><\/div>\n<p class=\"wp-block-paragraph\">I like to include screenshots in my articles. I find that a visual element helps the reader to understand what I&#8217;m describing. When showing how to do something in an app, I try to include full-size screenshots where I can. For example, in my article about how to <a href=\"https:\/\/www.both.org\/?p=14315\">format a book interior in LibreOffice<\/a>, I used lots of full-size screenshots.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But sometimes, I need to adjust a screenshot. One common example for my writing is when I make a screenshot of a DOS application, such as one running on FreeDOS. My other article about using the <a href=\"https:\/\/www.both.org\/?p=14056\">FED editor on FreeDOS<\/a> included several screenshots of the editor, running in a QEMU virtual machine. This is where I run into a problem: QEMU always represents pixels as square. This works well for graphics like the screenshots of <a href=\"https:\/\/www.both.org\/?p=14420\">Windows 3.11 running on FreeDOS<\/a>, but doesn&#8217;t work well for plain text windows\u2014like the &#8220;console mode&#8221; screenshots in the same article.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Classic PCs in the 1980s and 1990s used monitors with a 4:3 aspect ratio. Pixels were not square, so text mode did not use square pixels. Instead, the monitor would have displayed &#8220;console mode&#8221; text in the 4:3 aspect ratio. To make these screenshots look <em>right<\/em> for the 1980s and 1990s, I prefer to resize &#8220;console mode&#8221; screenshots to use the correct aspect ratio.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resizing with ImageMagick<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If I have a lot of screenshots to work with, I prefer to use a command line tool like <a href=\"https:\/\/imagemagick.org\/\">ImageMagick<\/a> to resize my images. ImageMagick should be available for every Linux distribution; if it is not installed on your system by default, you can install it using your system&#8217;s package manager, like this for Fedora-based systems:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo dnf install imagemagick<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Using the command line is just faster when I might have a dozen or more screenshots. But for this example, I&#8217;ll use just two images: one &#8220;console mode&#8221; screenshot and one that is from graphics mode.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"400\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/07\/screenshot1.png\" alt=\"editing a file in a text editor, the line &quot;InDOSPolling=TRUE&quot; is highlighted\" class=\"wp-image-14433\"\/><figcaption class=\"wp-element-caption\">a &#8220;console mode&#8221; screenshot (screenshot1.png)<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"480\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/07\/win311.png\" alt=\"several computer icons on a desktop: file manager, control panel, print manager, and others\" class=\"wp-image-14411\"\/><figcaption class=\"wp-element-caption\">a graphics mode screenshot (screenshot2.png)<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">The <code>identify<\/code> subcommand<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Older versions of ImageMagick provided separate commands for each action, such as <code>convert<\/code> or <code>identify<\/code>, but newer versions provide just one command name (<code>magick<\/code>) and the actions are usually <em>subcommands<\/em>. Let&#8217;s start with the <code>identify<\/code> subcommand to see the size of each screenshot.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ls -1 *.png\nscreenshot1.png\nscreenshot2.png\n\n$ magick identify screenshot*.png\nscreenshot1.png PNG 720x400 720x400+0+0 8-bit sRGB 9497B 0.000u 0:00.000\nscreenshot2.png PNG 640x480 640x480+0+0 8-bit sRGB 8295B 0.000u 0:00.000<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The &#8220;console mode&#8221; screenshot uses 720&#215;400 size, and the graphics mode screenshot is 640&#215;480 (a standard VGA resolution).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The <code>-resize<\/code> action<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You might wonder about the 720&#215;400 size. This is because VGA fonts used <a href=\"https:\/\/int10h.org\/oldschool-pc-fonts\/fontlist\/?1#subs-ibm-g2-vga\">9&#215;16 glyphs<\/a>, so each character was 9 pixels wide and 16 pixels tall. DOS &#8220;console mode&#8221; screens were typically 80&#215;25, so 80 columns and 25 lines. If you do the math, 9&#215;80 = 720 and 16&#215;25 = 400.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But original VGA monitors only displayed video in 4:3 aspect ratio. That means I need to resize the &#8220;console mode&#8221; screenshot to display it in its original 4:3 aspect ratio. If I don&#8217;t want to lose the <em>y<\/em> resolution (400) I only need to resize the <em>x<\/em> dimension. Doing a little more math, that means the <em>x<\/em> size needs to be 400&#215;4\/3 = 533 pixels.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I can use the <code>-resize<\/code> action to change the dimensions of an image. However, by default this will only resize the image to fit <em>within<\/em> a certain size. If I try to resize the <em>screenshot1.png<\/em> image to fit in a 533&#215;400 size, the image will actually be too small:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ magick screenshot1.png -resize '533x400' new.png\n\n$ magick identify new.png \nnew.png PNG 533x296 533x296+0+0 8-bit sRGB 59859B 0.000u 0:00.000<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To force the new image to be <em>exactly<\/em> a certain size, I need to append an exclamation point to the end of the resized dimension:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ magick screenshot1.png -resize '533x400!' new.png\n\n$ magick identify new.png\nnew.png PNG 533x400 533x400+0+0 8-bit sRGB 38046B 0.000u 0:00.000<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Converting a set of images<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If I only have a few images to convert to the new size, I might run that command separately for each image. In that case, using <code>identify<\/code> to check the size and the <code>-resize<\/code> action to change the size for a few &#8220;console mode&#8221; screenshots is not too much trouble. But when I make screenshots for an article, I usually capture more than a dozen screenshots, and sort through them later. Converting these one at a time is too much work for me; I&#8217;d rather automate that.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To automate a set of images, I start with a feature of the <code>identify<\/code> subcommand to display certain image characteristics using <em>fields<\/em>. For example, <code>%w<\/code> and <code>%h<\/code> will show the width and height of an image. Use these fields in a <code>-format<\/code> action to print just the dimensions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ magick identify -format '%wX%h' new.png\n533X400<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Or, if I wanted to automate that for a set of screenshots, I could use Bash <em>shell expansion<\/em> with <code>$( )<\/code> to save the output of the <code>identify<\/code> subcommand in a variable, so I can use it later:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ for f in screenshot*.png; do dim=$(magick identify -format '%wX%h' $f); echo $dim $f; done\n720X400 screenshot1.png\n640X480 screenshot2.png<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And that is how I automate resizing a collection of screenshots, but preserving the resolution for graphics mode screenshots while resizing any &#8220;console mode&#8221; screenshots to use 4:3 aspect ratio. To do this, I use Bash <em>conditional evaluation<\/em> to compare a variable&#8217;s value (like <code>dim<\/code>) and take action if the variable is (or is not) the <code>720X400<\/code> value. Again, I only have two screenshots in this example, but the process is the same for two images as it would be for a dozen or more:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ for f in screenshot*.png; do dim=$(magick identify -format '%wX%h' $f); &#91; $dim = '720X400' ] &amp;&amp; magick $f -resize '533x400!' new$f; done<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">There&#8217;s a lot going on in this (very long) command line, but the only new part is the conditional evaluation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91; $dim = '720X400' ] &amp;&amp; magick $f -resize '533x400!' new$f<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This performs a test: is the <code>dim<\/code> variable equal to the <code>720X400<\/code> value? If it is, then Bash executes the <code>magick<\/code> command with the <code>-resize<\/code> action to force the screenshot to the 4:3 aspect ratio. If the image is some other size, nothing happens.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After running this <code>for<\/code> command on my two screenshots, I actually end up with three images: the two original screenshots, plus one &#8220;console mode&#8221; screenshot that has been resized to 533&#215;400 resolution:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ magick identify *screenshot*png\nnewscreenshot1.png PNG 533x400 533x400+0+0 8-bit sRGB 38046B 0.000u 0:00.000\nscreenshot1.png PNG 720x400 720x400+0+0 8-bit sRGB 9497B 0.000u 0:00.000\nscreenshot2.png PNG 640x480 640x480+0+0 8-bit sRGB 8295B 0.000u 0:00.000<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"400\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/07\/screenshot1.png\" alt=\"editing a file in a text editor, the line &quot;InDOSPolling=TRUE&quot; is highlighted\" class=\"wp-image-14433\"\/><figcaption class=\"wp-element-caption\">the original &#8220;console mode&#8221; screenshot (screenshot1.png)<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"400\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/07\/edit-system-ini.png\" alt=\"editing a file in a text editor, the line &quot;InDOSPolling=TRUE&quot; is highlighted\" class=\"wp-image-14410\"\/><figcaption class=\"wp-element-caption\">the resized &#8220;console mode&#8221; screenshot (newscreenshot1.png)<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Command line for the win<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I could have used an app like GIMP to resize the &#8220;console mode&#8221; screenshot; this doesn&#8217;t take very long, probably a few seconds. And that&#8217;s not a big difference for just one or two screenshots.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But if you&#8217;re working with a dozen or more screenshots, &#8220;a few seconds&#8221; for each image quickly adds up to a lot of time. It&#8217;s much faster to use the command line for these kinds of &#8220;batch&#8221; operations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s how to selectively resize images from the command line<\/p>\n","protected":false},"author":33,"featured_media":4464,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":"","_members_access_role":[],"_members_access_error":""},"categories":[100,5],"tags":[104,91],"class_list":["post-14434","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-line","category-linux","tag-command-line","tag-linux"],"modified_by":"Jim Hall","_links":{"self":[{"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14434"}],"version-history":[{"count":6,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14434\/revisions"}],"predecessor-version":[{"id":14440,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14434\/revisions\/14440"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/4464"}],"wp:attachment":[{"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14434"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}