crop empty space around 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
tester

crop empty space around images

Post by tester »

Hi,

Is there a way to -crop "automatically" the white border or empty space around the images like e.g. with gimp?
Please let me know how to solve this because I miss the option at the crop manual page :-/

Thanks a lot
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: crop empty space around images

Post by Bonzo »

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: crop empty space around images

Post by fmw42 »

also see -fuzz to allow your trim to be less sensitive to slight color variations in the area you want to trim.

see http://www.imagemagick.org/script/comma ... s.php#fuzz

for example,

convert image -fuzz 1% -trim +repage result

The +repage removes the virtual canvas which is the size of the input and makes the output just the trimmed size.

see http://www.imagemagick.org/Usage/crop/#trim
jauson
Posts: 36
Joined: 2015-05-04T21:05:35-07:00
Authentication code: 6789

Re: crop empty space around images

Post by jauson »

I had an issue with a png having a slight bit of transparency, which resulted in removing the transparency part, and leaving the white areas. To fix it, first I had to flatten, then trim.

Code: Select all

convert partial-trans.png -flatten -fuzz 1% -trim +repage trimmed.jpg
Post Reply