06 August 2008

ImageMagick crops your white space!

ImageMagick is a fabulous command-line tool for image processing. I use it a lot for converting between different image formats, which it does with no fuss whatsoever -- as the following PNG to PDF example illustrates:

$ convert in.png out.pdf

ImageMagick can do much, much more than conversions. Today I learned the following trick from an
e-mail list discussion:

$ convert -trim img.pdf

which trims all the white space from around an image. It's a great trick for inserting Matlab plots into papers! I used to do this by hand with an image editing program like the GIMP; it's great to know that I don't have to fire up such a massive tool in order to accomplish this simple task. (The GIMP is a wonderful program, incidentally, but starting it up just to crop some white space is a task beneath its mighty powers.)

8 comments:

John said...

I just had occasion to use it. That works great!

HilbertAstronaut said...

*grins* I feel useful :-D

Matt Beedle said...

hurruh, just what I was looking for. Thanks very much!

Snails777 said...

sweet!
Didnt need it, but used it anyhow.

Zeeshan Muhammad said...

Thank you for much for posting this tip!

We make use of ImageMagic heavily to form previews of stock photos, "-crop 0x0" tip works wonders on line-art and vector drawings :-)

A good example of this in play on our site: http://www.clipartstar.com/photos/ew3hwc/environmental-energy-symbols

Thank you again!

- Clipart Star team

Zeeshan Muhammad said...

Thank you for much for posting this tip!

We make use of ImageMagic heavily to form previews of stock photos, "-crop 0x0" tip works wonders on line-art and vector drawings :-)

A good example of this in play on our site: http://www.clipartstar.com/photos/ew3hwc/environmental-energy-symbols

Thank you again!

- Clipart Star team

Paul said...

I think you mean 'mogrify' rather than 'convert' (with 'convert' you need to specify an output file).

I also found the option -fuzz <%age> useful when using -trim as my white space wasn't as white as it might seem when looked at close up. 8% worked well for me.

HilbertAstronaut said...

Thanks Paul!