trim whitespace or "punching out" images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Posts: 7
Joined: 2013-01-07T06:13:17-07:00
Authentication code: 6789

trim whitespace or "punching out" images

Post by arpeggio »

Hi Guys,

I've been trying numerous ways to achieve this but just cant seem to even really get started and dont even know if it's possible either!
I'm really hoping someone can help or offer direction pls.
i have 4 photos (usually scenery) on one page. Each photo is separated by a little whitespace.
I want to "punch out" these images and make 4 separate images.

Is this possible? and if so how?

Thank you very much for all inputs.

Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: trim whitespace or "punching out" images

Post by snibgo »

If you know the dimensions of each photo, or they are the same size, it's quite easy. See

If the photos vary in size, I think you'll need a script to find each whitespace separation. Then use that data to crop out each photo, and trim them.
snibgo's IM pages:
User avatar
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: trim whitespace or "punching out" images

Post by fmw42 »

If your images are well separate by some constant color such as pure white (or close to white) and you are on unix/mac or windows/cygwin, you can use my unix shell script, multicrop, at the link below.
User avatar
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: trim whitespace or "punching out" images

Post by anthony »

Basically it helps us to have an example of what you are working with. We can then experiment ourselves and give you a better solution.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
Post Reply