Wednesday, March 9, 2011

Images and Photo tagging from cmdline using ImageMagick in LINUX

Adding a copyright or tag to your pictures:
   Want a really fast command to add a comment or protect your photos, graphics, or other images, from the command line (LINUX)?
   I wanted to add a comment to a screenshot I took from google-earth.  The file format was .png and I'm using Fedora 14 on this pc.  There are plenty of ways to add comments with extra steps, but I wanted a simple, one-liner to do this.
  I found a lot of really cool things this powerful software is capable of doing.
cool stuff I made: polaroid effect on pictures, copyright to put on stuff, a proof tag for work I do for clients.

Ever see copyrights or other text on photos online? I was wanting to do this without opening GIMP or other photo editing programs and came across this cool script to do just that.  You need ImageMagick (link to examples), because convert is part of this package.

Make sure you have ImageMagick by doing the following, in a terminal window:
$sudo yum info ImageMagick
Installed Packages
Name      : ImageMagick
Arch        :x86_64
Version   :6.6.4.1
Release   :15.fc14
Size         :6.7 M

or, what I did:
$sudo yum whatprovides "/usr/bin/convert"
 ImageMagick-6.6.4.1-15.fc14.x86_64 : An X application for displaying and
                                   : manipulating images
Repo        : installed
Matched from:
Filename    : /usr/bin/convert

To see all the details of what convert can do:
$man convert
<here's basic info on convert from that manpage info>
manpage description:
convert  -  convert  between  image formats as well as resize an image, blur,
       crop, despeckle, dither, draw on, flip, join, re-sample, polaroid effect, and much more. Go here for a list of the switches, their usage, and descriptions.
I'll use this image for my example PELICAN.jpg (38KB, 187 x 209)
Open terminal and "cd" to your Desktop, or where your image is you wish to tag.  Then with the following command:
$/usr/bin/convert -font Utopia-Bold -fill white -gravity South -draw 'text 10,2 "Pelican-DSPrinting"' Pelican.jpg NewPelican.jpg
 Results in this new image:
Simple tagging of an image (for example, 428x521, 43.8k in size):
$/usr/bin/convert -font Utopia-Bold -pointsize 26 -fill Red -gravity SouthWest -draw 'text 15,24 "Whatever you want"' InputPic.png outputPic.png

If it's a large (read high quality Megapixel image) then you'll need to adjust the pointsize switch, like this...
$/usr/bin/convert -font Utopia-Bold -pointsize 48 -fill Blue -gravity SouthWest -draw 'text 15,24 "Whatever you want"' InputPic.png OutputPic.png

If you leave out the -font switch, convert will use a default font.
To list the fonts you have available:
$/usr/bin/convert -list font

No comments:

Post a Comment