5 ImageMagick command line examples part 2

I've put together another 5 ImageMagick command line examples as a followup to part 1. These examples are a little more advanced and include some extra information on techniques.

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

1. Resizing an image.

Resizing seems to be a very common task that people need automated. With convert you can easily write a script that resizes call images in a directory. Before you start resizing images it helps if you read a howto on resizing digital images.

Example:

convert flower_original.jpg -resize 640x480 flower.jpg

Produces:

For more in depth examples of resizing check out the examples page and the convert -resize options. If you are interested in the output of the different filter types check out these examples of each of them at different levels.

2. Sharpening an image.

Sharpening an image can bring out some details that get lost when you resize or compress an image. I came across an article about using sharpen to make a picture look better and went off to find a way to reproduce the results with ImageMagick. It wasn't easy but I found another article on sharpening with ImageMagick. I have found the following command works the best:

Example:

convert flower.jpg -unsharp 1.5x1.0+1.5+0.02 flower_unsharp.jpg

Produces:

For more information on sharpening see this example page and the -unsharp option.

3. Changing image formats

ImageMagick supports a wide range of image formats and you can use convert to change one format into another. Some formats have optional commands that can be given to change the output. An example of that would be png and jpg quality.

Example (jpg to png):

convert flower.jpg -quality 95 flower_quality.png

Produces:

Example: (jpg to jpg – lower quality):

convert flower.jpg -quality 80% flower_quality.jpg

Produces:

PNGs have a different type of quality setting than JPGs. You can read more about the different options on the example page or the -quality option.

4. Adding a raised border

Adding a frame around an image can come in handy. With ImageMagick there is nothing to it.

Example (simple raised border):

convert flower.jpg -frame 6x6+2+2 flower_frame1.jpg

Produces:

Example (raised with annotation):

convert flower.jpg -mattecolor grey -background grey -frame 3x3+0+3 -gravity South -splice 0x15 -annotate 0x0 'Flower' -frame 6x6+3+0 flower_frame2.jpg

Produces:

To see all the options you have with frames see the examples.

5. Buttons

This example shows how to make "gel" buttons. It could be modified to make buttons for a website.

Example:

convert -size 100x60 xc:none -fill red -draw 'circle 25,30 10,30' \
-draw 'circle 75,30 90,30' -draw 'rectangle 25,15 75,45' gel_shape.png

Produces:

Example:

convert gel_shape.png \( +clone -fx A +matte  -blur 0x12  -shade 110x0 -normalize \
-sigmoidal-contrast 16,60% -evaluate Multiply .5 -roll +5+10 +clone -compose Screen -composite \) \
-matte -compose In -composite gel_highlight.png

Produces:

Example:

convert gel_highlight.png \( +clone -fx A  +matte -blur 0x2  -shade 0x90 -normalize \
-blur 0x2  -negate -evaluate multiply .4 -negate -roll -.5-1 +clone  -compose Multiply -composite \) \
-matte -compose In -composite gel_border.png

Produces:

Example:

convert gel_border.png -font AvantGarde-Book -pointsize 24 -fill white \
-gravity Center -annotate 0 "Gel" -trim +repage -bordercolor none -border 4  \
\( +clone -background navy -shadow 80x4+4+4 \) +swap -background none -flatten gel_button.png

Produces:

See this example for more information.

If you are interested here is a link to all the examples in one file.

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *