{"id":8777,"date":"2024-12-04T03:00:00","date_gmt":"2024-12-04T08:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=8777"},"modified":"2024-12-01T11:29:01","modified_gmt":"2024-12-01T16:29:01","slug":"use-imagemagick-to-work-with-images","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=8777","title":{"rendered":"Use ImageMagick to work with images"},"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=\"8777\" 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\">    <\/span>\r\n<\/div><\/div>\n<p>ImageMagick is a handy multipurpose command-line tool for all your image needs. Available from the command line simply as <strong>magick<\/strong>, ImageMagick supports a variety of image types, including JPG photos and PNG graphics.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"identifying-images\">Identifying images<\/h2>\n\n\n\n<p>I often use ImageMagick on my webserver to resize images. For example, let\u2019s say I want to share a photo of a little food delivery robot that I passed on the street, and put it on my website. I took this photo with the default resolution from my phone. But even though it\u2019s cropped into a square image, I wonder if it\u2019s still too big to share on a website. I can use the <strong>identify<\/strong> subcommand to tell me about the dimensions of my image:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ magick identify PXL_20241016_175002510.jpg \nPXL_20241016_175002510.jpg JPEG 2268x2268 2268x2268+0+0 8-bit sRGB 1.642MiB 0.000u 0:00.001<\/code><\/pre>\n\n\n\n<p>The output tells me the image is 2268&#215;2268, and over 1.6MB in size. That\u2019s much too large for a website.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"resizing-images\">Resizing images<\/h2>\n\n\n\n<p>Let\u2019s use ImageMagick to change the size of my photo so that I can include it on my web page. ImageMagick is a full suite of tools. One of the most common features I use is the <strong>-resize<\/strong> subcommand.<\/p>\n\n\n\n<p>To resize my photo to a more manageable 500-pixel width, type this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ magick PXL_20241016_175002510.jpg -resize 500x500 robot.jpg<\/code><\/pre>\n\n\n\n<p>The new image is only 120kB in size:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ magick identify robot.jpg \nrobot.jpg JPEG 500x500 500x500+0+0 8-bit sRGB 119990B 0.000u 0:00.004<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"500\" height=\"500\" src=\"https:\/\/www.both.org\/wp-content\/uploads\/2024\/12\/robot.jpg\" alt=\"\" class=\"wp-image-8778\"\/><figcaption class=\"wp-element-caption\">A food delivery robot<\/figcaption><\/figure>\n\n\n\n<p>You can provide both width and height dimensions with the <strong>-resize<\/strong> option, as I\u2019ve done here. If you provide only the width (like <strong>500x<\/strong>) ImageMagick does the math for you and automatically retains the aspect ratio by resizing the output image with a proportional height.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"install-imagemagick-on-linux\">Install ImageMagick on Linux<\/h2>\n\n\n\n<p>On Linux, you can install ImageMagick using your package manager. For instance, on Fedora or similar:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo dnf install imagemagick<\/code><\/pre>\n\n\n\n<p>On Debian and similar:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo apt install imagemagick<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><em>This article is adapted from <a href=\"https:\/\/opensource.com\/article\/21\/9\/resize-image-linux\">Resize an image from the Linux terminal<\/a> by Jim Hall, and is republished with permission from the author.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ImageMagick is a handy multipurpose command-line tool for all your image needs.<\/p>\n","protected":false},"author":33,"featured_media":3293,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[100,291],"tags":[104,147],"class_list":["post-8777","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-command-line","category-digital-images","tag-command-line","tag-fun"],"modified_by":"Jim Hall","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/8777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8777"}],"version-history":[{"count":1,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/8777\/revisions"}],"predecessor-version":[{"id":8779,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/8777\/revisions\/8779"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/3293"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}