How to crop immage to first non white pixel from edges

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
hogo
Posts: 1
Joined: 2016-12-29T02:55:31-07:00
Authentication code: 1151

How to crop immage to first non white pixel from edges

Post by hogo »

Using slow satellite connection and need to crop white space around scanned image. Image is not always in right position (can be rotated a bit) and size is different.
I need to find first non white pixel from the edge from all 4 sides. Then crop image.

Is there direct function for it or I need to play around.

Thank you for help.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to crop immage to first non white pixel from edges

Post by snibgo »

There is no direct function for this. I show a method on my "Inner trim" page, including a Windows BAT script.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to crop immage to first non white pixel from edges

Post by fmw42 »

Are you trying to remove the outer white area? If so, then try -trim. See http://www.imagemagick.org/Usage/crop/#trim

You can also unrotate the image using -deskew (before trimming), if the rotation is less than about 5 deg. See http://www.imagemagick.org/script/comma ... php#deskew. If on a Unix-type platform, you can try my script, unrotate at my link below.

Please always provide your IM version and platform, since syntax may differ. An example image always helps, too.
Post Reply