How to automatically crop a picture

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
projetmbc

How to automatically crop a picture

Post by projetmbc »

Hello,
I have a picture with a white background. I would like to find the minimal rectangle around the picture, more precisely the rectangle must start at the first non white pixels.

Here is a way to do that with imagemagick ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to automatically crop a picture

Post by fmw42 »

I don't think -trim will guarantee that the rectangle starts with the first non-white pixel. Say you have a black circle in a white background. Then -trim will have a minimum size image that has white in the top left corner, but has back at the center of the sides of the circle.

Please clarify your request further. Or present an example (diagram or image) that you think shows what you want!

You may also want to look at my scripts, autotrim and trimmer. see link below
Post Reply