Unable to trim whitespace from this image

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
chaddjohnson
Posts: 14
Joined: 2018-11-27T20:59:27-07:00
Authentication code: 1152

Unable to trim whitespace from this image

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unable to trim whitespace from this image

Post 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
chaddjohnson
Posts: 14
Joined: 2018-11-27T20:59:27-07:00
Authentication code: 1152

Re: Unable to trim whitespace from this image

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unable to trim whitespace from this image

Post 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.
chaddjohnson
Posts: 14
Joined: 2018-11-27T20:59:27-07:00
Authentication code: 1152

Re: Unable to trim whitespace from this image

Post 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 :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unable to trim whitespace from this image

Post 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
chaddjohnson
Posts: 14
Joined: 2018-11-27T20:59:27-07:00
Authentication code: 1152

Re: Unable to trim whitespace from this image

Post by chaddjohnson »

Will do. Thanks!
Post Reply