{"id":274,"date":"2011-07-06T12:33:12","date_gmt":"2011-07-06T11:33:12","guid":{"rendered":"http:\/\/all-geo.org\/volcan01010\/?p=274"},"modified":"2011-07-06T13:07:49","modified_gmt":"2011-07-06T12:07:49","slug":"figures-with-imagemagick","status":"publish","type":"post","link":"https:\/\/all-geo.org\/volcan01010\/2011\/07\/figures-with-imagemagick\/","title":{"rendered":"Quick, multipart, annotated figures with ImageMagick"},"content":{"rendered":"<p>This is the first post so far that is much <a href=\"http:\/\/all-geo.org\/volcan01010\/about\/\">more 01010 than volcan<\/a>.\u00a0 As well as discussing volcanology, an aim of this blog is to share some of the computing methods involving <a href=\"http:\/\/en.wikipedia.org\/wiki\/Free_and_open_source_software\">free software<\/a> that I use each day in my work.\u00a0 I am sure that many people will find them useful, both inside and outside the worlds of science and academia.<\/p>\n<h3>ImageMagick<\/h3>\n<p><a title=\"ImageMagick\" href=\"http:\/\/www.imagemagick.org\/\" target=\"_blank\">ImageMagick<\/a> is a command-line program for manipulating images.\u00a0 It is installed as standard on most Linux distributions and can be installed for Windows or Mac from <a href=\"http:\/\/www.imagemagick.org\/script\/binary-releases.php\">here<\/a>.\u00a0 Although it can take a while to learn the commands, once you know them you can do things really quickly.\u00a0 Furthermore, you can link them into a script to perform complicated manipulations on lots of images automatically.<\/p>\n<p>This post shows how to use ImageMagick to overlay simple text annotations onto images, and to combine them to produce a multipart figure.\u00a0 In this case, the command line method is\u00a0 significantly quicker and easier than opening a clunky program such as Corel Draw or Adobe Illustrator and doing it by hand.<\/p>\n<h3>Annotating the image<\/h3>\n<div id=\"attachment_277\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/all-geo.org\/volcan01010\/wp-content\/uploads\/2011\/07\/a_logo.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-277\" class=\"size-full wp-image-277\" src=\"http:\/\/all-geo.org\/volcan01010\/wp-content\/uploads\/2011\/07\/a_logo.png\" alt=\"Annotated volcan01010 logo\" width=\"490\" height=\"260\" srcset=\"https:\/\/all-geo.org\/volcan01010\/wp-content\/uploads\/2011\/07\/a_logo.png 490w, https:\/\/all-geo.org\/volcan01010\/wp-content\/uploads\/2011\/07\/a_logo-300x159.png 300w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/a><p id=\"caption-attachment-277\" class=\"wp-caption-text\">The volcan01010 logo has been annotated with (a) on a semi-transparent white background using the example command.<\/p><\/div>\n<pre>convert volcan01010_logo_white.png -resize 490x260 \\\r\n-background '#ffffffa0' -fill black \\\r\n-font Helvetica-bold -pointsize 28 \\\r\nlabel:' (a) ' \\\r\n-gravity northwest -geometry +10+12 \\\r\n-composite a_logo.png<\/pre>\n<p>The command breaks down as follows:<\/p>\n<ul>\n<li><span style=\"color: #99cc00\"><a href=\"http:\/\/www.imagemagick.org\/script\/convert.php\">convert<\/a><\/span>:\u00a0 One of the ImageMagick programs.<\/li>\n<li><span style=\"color: #99cc00\">volcan01010_logo_white.png<\/span>:\u00a0 The input file name.<\/li>\n<li><span style=\"color: #99cc00\">-resize 490&#215;260<\/span>:\u00a0 Resize image to 490&#215;260 pixels wide.<\/li>\n<li><span style=\"color: #99cc00\">-background &#8216;#ffffffa0&#8217;<\/span>:\u00a0 Set the colour of the text background, using <a href=\"http:\/\/www.imagemagick.org\/script\/color.php\">hex codes<\/a>.\u00a0 The last two digits control transparency (00: transparent, ff: opaque).\u00a0 You can also use <em>none<\/em>.<\/li>\n<li><span style=\"color: #99cc00\">-fill black<\/span>:\u00a0 Set the text colour.\u00a0 Hex codes can also be used.<\/li>\n<li><span style=\"color: #99cc00\">-font Helvetica-bold -pointsize 28<\/span>:\u00a0 Set the font and size.<\/li>\n<li><span style=\"color: #99cc00\">label: &#8216; (a) &#8216;<\/span>:\u00a0 The text to write.\u00a0 You can also use this to label different parts of a figure, or to give an image a title.\u00a0 The extra spaces give a padded box.<\/li>\n<li><span style=\"color: #99cc00\">-gravity northwest -geometry +10+12<\/span>:\u00a0 Text positioning, in pixels from a chosen corner.<\/li>\n<li><span style=\"color: #99cc00\">-composite<\/span>:\u00a0 Overlays the label on the image.<\/li>\n<li><span style=\"color: #99cc00\">a_logo.png<\/span>:\u00a0 Output file name.<\/li>\n<\/ul>\n<p>Note that the backslashes &#8216; \\ &#8216; are to tell the computer that the code continues onto a new line.\u00a0 This makes it easier to read, especially on the blog.\u00a0 They aren&#8217;t necessary if the command is entered on one long line.<\/p>\n<p>It often takes a bit of trial and error to get the correct settings for the font size and position, as they depend on the size of the image.\u00a0 The images here are quite small; a single column image in a scientific journal should be about 1600 pixels wide (for printing at 500 dpi).<\/p>\n<h3>Combining the images into a multipart figure<\/h3>\n<div id=\"attachment_275\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/all-geo.org\/volcan01010\/wp-content\/uploads\/2011\/07\/multipart.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-275\" class=\"size-full wp-image-275 \" src=\"http:\/\/all-geo.org\/volcan01010\/wp-content\/uploads\/2011\/07\/multipart_small.png\" alt=\"Multipart images\" width=\"600\" height=\"324\" srcset=\"https:\/\/all-geo.org\/volcan01010\/wp-content\/uploads\/2011\/07\/multipart_small.png 600w, https:\/\/all-geo.org\/volcan01010\/wp-content\/uploads\/2011\/07\/multipart_small-300x162.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><p id=\"caption-attachment-275\" class=\"wp-caption-text\">The multipart figure using annotated images, combined with the montage command.  (a) Original.  (b) Rotated 180 degrees.  (c) Negative.  Note the semi-transparent background on the annotation.  (d) Motion blur.<\/p><\/div>\n<pre>montage a_logo.png b_rotated.png c_negative.png d_motion_blur.png \\\r\n-tile 2x2 -geometry +5+5 multipart.png<\/pre>\n<p>The command breaks down as follows:<\/p>\n<ul>\n<li><span style=\"color: #99cc00\"><a href=\"http:\/\/www.imagemagick.org\/script\/montage.php\">montage<\/a><\/span>:\u00a0 One of the ImageMagick programs.<\/li>\n<li><span style=\"color: #99cc00\">a_logo.png &#8230; d_motion_blur.png<\/span>:\u00a0 Input file names.<\/li>\n<li><span style=\"color: #99cc00\">-tile 2&#215;2<\/span>:\u00a0 Sets how the images are laid out.<\/li>\n<li><span style=\"color: #99cc00\">-geometry +5+5<\/span>:\u00a0 Controls the size and spacing of the images.<\/li>\n<li><span style=\"color: #99cc00\">multipart.png<\/span>:\u00a0 Output file name.<\/li>\n<\/ul>\n<h3>Other uses for ImageMagick<\/h3>\n<p>There are a host of other supremely useful functions in ImageMagick.\u00a0 The convert command is primarily used to convert between formats e.g. jpg, tif, png.\u00a0 Some of the other commands or options that I frequently use are listed below.\u00a0 If you Google them, you can find full instructions.<\/p>\n<ul>\n<li><span style=\"color: #99cc00\">mogrify<\/span>:\u00a0 Change an image in-situ e.g. input file = output file.<\/li>\n<li><span style=\"color: #99cc00\">-rotate 90<\/span>:\u00a0 Rotate image.<\/li>\n<li><span style=\"color: #99cc00\">-trim<\/span>:\u00a0 Remove unnecessary white border from around an image.<\/li>\n<li><span style=\"color: #99cc00\">-bordercolor white -border 2&#215;2<\/span>:\u00a0 Add border of chosen size and colour.<\/li>\n<li><span style=\"color: #99cc00\">-colorspace Gray<\/span>:\u00a0 Convert to grayscale.<\/li>\n<li><span style=\"color: #99cc00\">-append<\/span>:\u00a0 Join two images together.<\/li>\n<li><span style=\"color: #99cc00\">-composite<\/span>:\u00a0 Overlay one image over another (e.g. a logo or watermark).<\/li>\n<li><span style=\"color: #99cc00\">-blend<\/span>:\u00a0 Blend one image into another (e.g. a logo or watermark).<\/li>\n<li><span style=\"color: #99cc00\">+repage<\/span>:\u00a0 Sometimes necessary to scale png files correctly.<\/li>\n<li><span style=\"color: #99cc00\">-fuzz 2% -transparent white<\/span>:\u00a0 Replace white with transparent (in png files).<\/li>\n<li><span style=\"color: #99cc00\">-shadow<\/span>:\u00a0 Add a shadow to an image.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This is the first post so far that is much more 01010 than volcan.\u00a0 As well as discussing volcanology, an aim of this blog is to share some of the computing methods involving free software that I use each day &hellip; <a href=\"https:\/\/all-geo.org\/volcan01010\/2011\/07\/figures-with-imagemagick\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3,8],"class_list":["post-274","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-3","tag-imagemagick"],"_links":{"self":[{"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/posts\/274","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/comments?post=274"}],"version-history":[{"count":15,"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/posts\/274\/revisions"}],"predecessor-version":[{"id":290,"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/posts\/274\/revisions\/290"}],"wp:attachment":[{"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/media?parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/categories?post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/all-geo.org\/volcan01010\/wp-json\/wp\/v2\/tags?post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}