Introduction
ImageMagick is free software delivered as a ready-to-run binary distribution or as source code that you can freely use, copy, modify, and distribute. Its license is compatible with the GPL. It runs on all major operating systems.
The functionality of ImageMagick is typically utilized:
- from the command line or
- from programs written in your favorite programming language. Choose from these interfaces: MagickCore (C), MagickWand (C), ChMagick (Ch), Magick++ (C++), JMagick (Java), L-Magick (Lisp), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK). With a language interface, use ImageMagick to modify or create images automagically and dynamically.
We point the interested reader to http://www.imagemagick.org for the full documentation, download and installation of the software.
Conversion of file formats
The command line tool to convert from one graphics format to another is convert. The basic usage is straight forward:convert Ashwinie_Jassvendra.png Ashwinie_Jassvendra.jpgThe convert command guesses the required format from the filename extension (i.e. from png to jpg).
Ashwinie_Jassvendra.png
Identifying image types
The identify command allows quick identification of image files:
Jassvendra@slax:~# identify Ashwinie_Jassvendra.png
Ashwinie_Jassvendra.png PNG 632x474 632x474+0+0 8-bit
DirectClass 815KB 0.040u 0:00.039 Ashwinie_Jassvendra.png PNG 632x474 632x474+0+0 8-bit
Jassvendra@slax:~# identify Ashwinie_Jassvendra.jpg
Ashwinie_Jassvendra.jpg JPEG 632x474 632x474+0+0 8-bit
Ashwinie_Jassvendra.jpg JPEG 632x474 632x474+0+0 8-bit
DirectClass 65.6KB 0.000u 0:00.000
Changing the size
First, we'll make the image we have somewhat smaller. For example, suppose we would like to limit it to 250 pixel in the x-direction:
convert -geometry 250 Ashwinie_Jassvendra.png small_Ashwinie_Jassvendra.pngThe number of pixels in the other direction (i.e. y) will be chosen such that the proportions of the image are preserved:
Jassvendra@slax:~# identify small_Ashwinie_Jassvendra.png
small_Ashwinie_Jassvendra.png PNG 250x188 250x188+0+0 8-bit DirectClass 104KB 0.020u 0:00.019
Here is the smaller image:
Adding a frame
Actually, the size of the image would be better visible if we had a frame around the image. Here is the command to create a frame of 2 pixels in color black:
convert -geometry 250 -border 2 -bordercolor black small_Ashwinie_Jassvendra.png small_frame.png
Adding labels
There is a multitude of possible ways to add labels to a picture. One is to use the montage command line utility which can create a montage by putting together several pictures. This is often used to create index thumbnail pages for directories with many pictures. Here, we put together our normal image, and a piece of text ("Jassvendra The Hero"):
Jassvendra@slax:~# montage -geometry +0+0 -background skyblue -label "Jassvendra The Hero" small_Ashwinie_Jassvendra.png small_label.pngwhich results in this picture
ImageMagick has a number of quite sophisticated image processing options which includes the polaroid switch:
Jassvendra@slax:~# convert -caption "Jassvendra The Hero Polaroid" small.png -gravity center -background black +polaroid small_polaroid.png
Labeling on top of the Image itself
The problem with writing text directly on a picture is that you can't be sure the text will be readable in the color you have chosen. The image being drawn onto could be black, white or a rainbow of colors.
Outlined Label: The simplest method is to draw the string with a outline to separate the text from the image. However as the "-stroke
" font setting adds thickness to a font both inward and outward, it is a good idea to draw the text twice.Jassvendra@slax:~# convert 06.jpg -gravity south -stroke '#000C' -strokewidth 2 -annotate 0 'nWo Computer LINUX' -stroke none -fill white -annotate 0 'nWo Computer LINUX' nwo.jpg
As you can see it works, but not very well. It does work better with a thicker font, than the default '
Times
' or 'Arial
' font. The more classical method to make the annotated text more visible is to 'dim" the image in the area the text will be added, then draw the text in the opposite color.Draw Dim Box: ImageMagick has the ability to draw transparent colors. This can be very useful to create a box to draw the text into.
Jassvendra@slax:~# convert 06.jpg -fill white -undercolor '#00000080' -gravity South -annotate +0+5 ' nWo Computer LINUX ' nwo03.jpg