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:
[code lang=”text”]convert flower_original.jpg -resize 640×480 flower.jpg[/code]

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:
[code lang=”text”]convert flower.jpg -unsharp 1.5×1.0+1.5+0.02 flower_unsharp.jpg[/code]

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):
[code lang=”text”]convert flower.jpg -quality 95 flower_quality.png[/code]

Produces:

Example: (jpg to jpg – lower quality):
[code lang=”text”]convert flower.jpg -quality 80% flower_quality.jpg[/code]

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):
[code lang=”text”]convert flower.jpg -frame 6×6+2+2 flower_frame1.jpg[/code]

Produces:

Example (raised with annotation):
[code lang=”text”]convert flower.jpg -mattecolor grey -background grey -frame 3×3+0+3 -gravity South -splice 0x15 -annotate 0x0 ‘Flower’ -frame 6×6+3+0 flower_frame2.jpg[/code]

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:
[code lang=”text”]
convert -size 100×60 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
[/code]

Produces:

Example:
[code lang=”text”]
convert gel_shape.png \( +clone -fx A +matte -blur 0x12 -shade 110×0 -normalize \
-sigmoidal-contrast 16,60% -evaluate Multiply .5 -roll +5+10 +clone -compose Screen -composite \) \
-matte -compose In -composite gel_highlight.png
[/code]

Produces:

Example:
[code lang=”text”]
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
[/code]

Produces:

Example:
[code lang=”text”]
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 80×4+4+4 \) +swap -background none -flatten gel_button.png
[/code]

Produces:

See this example for more information.

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

[tags]imagemagick, photo, linux[/tags]

5 thoughts on “5 ImageMagick command line examples part 2

  1. Leslie Hensley

    Tried using the gel technique for the buttons on my web site http://www.showerinabox.com/. For example the “Start Now” button on the home page. However the second step in your gel button example no longer works with recent versions of imagemagick. But luckily it still looks ok with that step omitted. What version of imagemagick are you using?

  2. carson Post author

    I’m using version 6.2.7 of ImageMagick. I just tried to cut and paste the gel examples and it looks like in firefox some of the values are being converted to binary. I’m going to add a link to all the examples in one script.

  3. Pingback: How to compile ImageMagick for PHP by hand @ IONCANNON

Comments are closed.