In ImageMagick the reference point is called -gravity, and upper left is the default. The positions set above uses the upper left image corner as reference. The maps show the average rain normalized soil moisture 2001-2016 for the Okavango Swamps, Botswana. $ convert -pointsize 24 -annotate +50+200 "Okavango" convert -pointsize 24 -annotate +50+200 "Okavango" The same image at 72 and 300 dpi, with pointsize set to 48 in both. If you try the same font size (expressed as -pointsize) on two copies of the same image, one at 72 dpi and the other at 300, you will get differently sized text on the two images. $ convert -units PixelsPerInch SrcImage.png -density 72 DstImage.png To change a png image to have 72 dpi, the command becomes: Do not change PixelsPerInch, it defines the -units to change. Where dpi is the dpi you want the DstImage to have. $ convert -units PixelsPerInch SrcImage.ext -density dpi DstImage.ext The latter has more advanced options available - see the ImageMagick manual. If you want to change the dpi, use the ImageMagick function -units, with either the parameter -density or -resample. You then get the width and height (in pixels) and the horizontal and vertical dpi. $ magick identify -format "%w x %h %x x %y" SrcImage.ext One option is the parameters -format, and to get the image size and resolution (dpi) execute the Terminal command: You can add different parameters to extend the returned metadata, as described in the ImageMagick manual. Which will return the most basic metadata, but not the dpi. You can use ImageMagick to query the image metadata (data about the image): For printing the most common is usually 300 or 600 dpi (or somewhere in between). dpi does not really matter for the internet, as modern web-browser ignore the dpi setting, but traditionally web images have been set to 72 dpi. You can set, or change, that using ImageMagick. How big your fonts are going to become then depends on the dpi that your image is set to. Where the parameter points is the font size in dots per inch (dpi). $ convert -pointsize points -annotate +startx+starty "annotation" SrcImage.ext DstImage.ext To define the font size, add the function -pointsize before -annotation: $ convert -annotate +20+30 "My map" SrcImage.png DstImage.png Font size and dpi If you want to write “My map” in the upper left corner (20 pixels from the left and 30 pixels from the top) on a png file, this then becomes: Where startx is the image column where the text should start, starty is the row where to start, and the quoted text that follows ( annotation) is the text to write SrcImage and DstImage are the source and destination images, with ext denoting the image file type. $ convert -annotate +startx+starty "annotation" SrcImage.ext DstImage.ext The basic command-line syntax to -annotate an image using ImageMagick is: The blog uses -annotate as the vehicle for explaining how to put text in images, and then I describe how I used -draw to put the embossed watermark text on the maps at the top of each page, and -caption label -label for setting text in pre-defined geometries. The general options for setting fonts, colors and postions are similar. Which function to use depends on how much and what type of control you want to have over the text that is written. The ImageMagick functions -annotate, -draw, -caption and -label can all be used for writing text to images. If this happens, try to use the option +repage, and ImageMagick adjusts the canvas to fit the layer. A canvas can contain more than one layer, and the positions you are setting the text at might be in the canvas but outside the layer. If ImageMagick does not put the text as you expected (or not text at all), the chance is that your layer is not filling up the canvas. The previous post is an introduction to ImageMagick. This post only covers how to use ImageImagick for putting text in images, and to create image compositions. This can not be done manually, and I chose to use ImageMagick. I also wanted to create animations from time-series of maps, and put both a caption, a time line and a clock in the image. This post is about putting a caption, label, watermark or other text directly in an image for web publishing.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |