5 ImageMagick command line examples – part 1

If you have ever wanted to manipulate images under linux you probably have used Gimp. This isn't your only option and if you want to do things from the command line a better option is to use ImageMagick's convert utility.

I've put together 5 simple command line examples that I have found useful. This is just a sample of what you can do with convert. To see more examples and get more explanation of options see: ImageMagick v6 Examples.

I started with the following image as a base for all the examples that follow:

1. Text annotations

Example (simple text in static location):

convert flower.jpg -font courier -fill white -pointsize 20 -annotate +50+50 'Flower' flower_annotate1.jpg

Produces:

Example (text with background at bottom):

convert flower.jpg -fill white -box '#00770080' -gravity South -pointsize 20 -annotate +0+5 '   Flower  ' flower_annotate2.jpg

Produces:

Look at these examples to see more.

2. Cropping an image

Example:

convert flower.jpg -crop 128x128+50+50 flower_crop.jpg

Produces:

Look at these examples or -crop for more information.

3. Rotate an image

Example:

convert flower.jpg -rotate 45 flower_rotate45.jpg

Produces:

Look at these examples or -rotate for more information.

4. Image montage

Example:

montage flower.jpg flower_unsharp.jpg -geometry '300x200+20+20' flower_montage.jpg

Produces:

Look at these examples to see more.

5. Animation

Example:

convert flower.jpg -resize 100x100 -font courier -fill white -pointsize 20 -annotate +50+50 'Frame 1' flower_frame1.gif
convert flower.jpg -resize 100x100 -font courier -fill white -pointsize 20 -annotate +50+50 'Frame 2' flower_frame2.gif
convert flower.jpg -resize 100x100 -font courier -fill white -pointsize 20 -annotate +50+50 'Frame 3' flower_frame3.gif
convert flower.jpg -resize 100x100 -font courier -fill white -pointsize 20 -annotate +50+50 'Frame 4' flower_frame4.gif
convert -delay 100 -size 100x100 \
   -page +0+0 flower_frame1.gif \
   -page +0+0 flower_frame2.gif \
   -page +0+0 flower_frame3.gif \
   -page +0+0 flower_frame4.gif \
   -loop 0 flower_animation.gif

Produces:

Look at these examples, these examples, or these examples for more information.

Summary

That is it for now. Part 2 should be up soon.

Tags: , ,

Leave a Reply

Your email address will not be published.