How can I -trim an image more aggressively?

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
bobhwantstoknow
Posts: 8
Joined: 2016-02-23T14:17:23-07:00
Authentication code: 1151

How can I -trim an image more aggressively?

Post by bobhwantstoknow »

Hello,

I have this image
Image
I can use the -trim option to produce this result
Image
I would like to achieve a more aggressive trim to produce a result like this
Image
Remove all of the border color while leaving the maximum possible remaining pixels. Is there a way to do that? I realize that there would be many cases that would produce a 0x0 image, but that won't be an issue in my case.

Debian Linux
Version: ImageMagick 6.8.9-9 Q16 i586 2015-01-05

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

Re: How can I -trim an image more aggressively?

Post by snibgo »

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 can I -trim an image more aggressively?

Post by fmw42 »

Why not just make the white into transparent? Or the white and black to transparent, leaving just the green, then trim to get the bounds of the green. Or make the white into black and trim.

Try this (unix syntax)

Code: Select all

convert t0NeV0C.png -fuzz 20% -fill black -opaque white -trim +repage result.png
bobhwantstoknow
Posts: 8
Joined: 2016-02-23T14:17:23-07:00
Authentication code: 1151

Re: How can I -trim an image more aggressively?

Post by bobhwantstoknow »

snibgo wrote:Fred has a bash script: http://www.fmwconcepts.com/imagemagick/ ... /index.php

This works great. Thanks.
Post Reply