Page 1 of 1

Unable to trim whitespace from this image

Posted: 2018-11-27T21:07:29-07:00
by chaddjohnson
I am trying to trim whitespace (which is actually transparent) from this image: https://i.ibb.co/MP9LcTh/image.png

The following command strangely fails to trim from the left side of the image:

Code: Select all

convert input.png -fuzz 5% -trim output.png
Any idea why?

Re: Unable to trim whitespace from this image

Posted: 2018-11-27T22:56:14-07:00
by fmw42
You have 1 opaque white row (not transparent) at the bottom of your image that is hard to detect. But you can see it if you turn alpha off and magnify your image. So you need to shave that off. Also you should remove the virtual-canvas after trimming with +repage.

Code: Select all

convert image.png -gravity south -chop 0x1 -fuzz 5% -trim +repage output.png

Re: Unable to trim whitespace from this image

Posted: 2018-11-28T12:36:36-07:00
by chaddjohnson
That was it! I totally missed that. Thank you! I was able to add some transparent padding like so:

Code: Select all

convert input.png -gravity north -background transparent -splice 0x1 output.png

Re: Unable to trim whitespace from this image

Posted: 2018-11-28T13:34:38-07:00
by fmw42
I am not sure why you needed to add the padding back for the one line that was removed, since you were trimming. But you added it to the top rather than the bottom where the line was removed by my chop.

Re: Unable to trim whitespace from this image

Posted: 2018-11-28T14:02:34-07:00
by chaddjohnson
It's due to the way this image was generated. It was composed with another image, and the mask was smaller than the other image, so that caused the line.

Sorry if I have my terms or usages wrong -- I'm a developer, and IM is new to me :)

Re: Unable to trim whitespace from this image

Posted: 2018-11-28T16:28:37-07:00
by fmw42
chaddjohnson wrote: 2018-11-28T14:02:34-07:00 Sorry if I have my terms or usages wrong -- I'm a developer, and IM is new to me :)
No problem. Just trying to understand why you added the transparent line to the top, since you were going to trim it anyway. Perhaps I misunderstand if you were adding it before or after processing. But no matter, as long is it is resolved for you.

Here are some helpful guidelines and links for new users.

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli

Re: Unable to trim whitespace from this image

Posted: 2018-11-28T16:39:58-07:00
by chaddjohnson
Will do. Thanks!