Thursday, 21 April 2011

Convert: The Image Conversion Tool

Many times command line tools are so cool and able than a GUI. I got to know about such a command line image conversion tool. It helped me complete my work so fast and efficient than many GUIs.

This tool does not come by default in ubuntu 10.10. You need to install imagemagick.

sudo apt-get install imagemagick

Giving you glimpse of what this amazing tool can do ... This is just a tip of the iceberg. You can do much much more using this ...

  1. Convert an Image from one Format to another (You can give any image format you know)

      $ convert a.jpg b.png

      $ convert a.bmp c.jpg

  2. To convert all files in folder

      $ convert *.jpg -set filename:name '%t' '%[filename:name].png'

  3. To convert all files in a folder and rename it as per your prefix

      $ convert *.jpg mynameprefix.png'

  4. To create a gif animation from the image files you have

      $ convert *.jpg mygif.gif

  5. To add a pause between transition in a gif image

      $ convert *.jpg -delay 100 mygif.gif

  6. To resize an image

      $ convert myimg.jpg -resize 50% myimgsmall.jpg

      $ convert myimg.jpg -resize 120x120 mythumbnail.jpg

        - To resize the image to pixel of 120 x 120 (width x height) image

  7. To add images to a pdf

      $ convert *.jpg photos.pdf

  8. Sometimes the image size will be too big but you can reduce it by reducing the quality(You may not be able to perceive it in computer screen)

      $ convert img.jpg -quality 75 new_img.jpg

      $ convert *.jpg -quality 75 mynameprefix.jpg

        - To convert all the jpg files and rename it to required prefix followed by sequential number

      $ convert *.jpg -quality 75 -set filename:name '%t' '%[filename:name].jpg'
      - To lower the quality without changing their name.

  9. To Add string to your file at a given location (0,0 denotes top left)

      $ convert myimg.jpg -draw 'text 100,200 “MY STRING”' mynewimg.jpg

      $ convert myimg.jpg -pointsize 20 -draw 'scale 1.5,1.5 text 100,200 “MY STRING”' mynewimg.jpg

          - This makes font size 20

      $ convert *.JPG -set filename:name '%t' -pointsize 36 -draw 'text 500,200 "COOL STUFF"' '%[filename:name].JPG'

  10. To make an image black and white

      $ convert myimg.jpg -colorspace gray myblack.jpg

      $ convert myimg.jpg -charcoal 5 myfun.jpg

        - It converts an image to pencil sketch the number indicates the thickness of line


For Further hacks refer to

http://www.imagemagick.org/Usage/

No comments:

Post a Comment