Page 2 of 3

Re: How to know the image's transparent space?

Posted: 2019-06-26T14:50:03-07:00
by niyanwen
I want to see if this image is fully transparent, if not I will trim this image as I mentioned above, so I cannot tell if it is transparent from detect transparency command right?

is there a way I can just know if this is a fully transparent image or not? I don't want to know some transparency

what is easiest and fastest way to do it? for we have a lot of image to processing, so want to reduce some time

Re: How to know the image's transparent space?

Posted: 2019-06-26T14:54:40-07:00
by niyanwen
in the other answer I saw you are using this command, is this the only way to do it?
convert transparent_image.png -channel a -separate -scale 1x1! -format "%[fx:mean]\n" info:

Re: How to know the image's transparent space?

Posted: 2019-06-26T15:26:26-07:00
by fmw42
I do not fully understand your question. Please clarify. Do you care if opaque around the edges of the image, but transparent inside the image?

If you want to know if the image is fully transparent everywhere, then the result would be 0 from my command. You can also tell if the image is fully opaque (no transparency) by using

Code: Select all

convert image -format "%[opaque]" info:
If returns true, it is fully opaque. If returns false, it has some (partial) transparency somewhere in the image.

See https://imagemagick.org/script/escape.php

convert transparent_image.png -channel a -separate -scale 1x1! -format "%[fx:mean]\n" info:
That works also. It just averages the image to 1 pixel first. I am not sure which is faster. You would have to test both ways.

Re: How to know the image's transparent space?

Posted: 2019-06-27T10:25:36-07:00
by niyanwen
thanks for you answer, in this case, I only care the image is fully transparent or not fully transparent, I think I would go with this command, if there is other shorter one, since I use java code, so shorter one might be clearer, but if not, it is fine
convert transparent_image.png -channel a -separate -scale 1x1! -format "%[fx:mean]\n" info:

Re: How to know the image's transparent space?

Posted: 2019-06-27T12:21:34-07:00
by snibgo
You don't need "-channel a -separate -scale 1x1" . Just use "%[fx:mean.a]", the mean of the alpha channel.

Re: How to know the image's transparent space?

Posted: 2019-07-01T20:55:33-07:00
by niyanwen
thanks, it works

I have another question, so currently I am running two commands in my java application. one is scale image, the other is remove transparent space and get image offset, what I mentioned in this post, but it running is too slow, is there a way to increase the processing speed?

Re: How to know the image's transparent space?

Posted: 2019-07-01T22:13:55-07:00
by niyanwen
one interesting thing is it is much slower because I used 7.X version in my java application, but if I switched to 6.9 version, it is much faster, but one compare command is starts fail

Re: How to know the image's transparent space?

Posted: 2019-07-01T22:20:17-07:00
by niyanwen
one compare image are same command starts fail and detect transparent image command did not work also
image magick version: 6.9.4_1

Re: How to know the image's transparent space?

Posted: 2019-07-01T22:54:43-07:00
by fmw42
This is an old post and the topics have changed since it was first posted. Please start a new question with your issue. It is not explained here very well.

ImageMagick 7 is slower than ImageMagick 6, because the default for ImageMagick 7 is HDRI enabled, which is not the case for ImageMagick 6. Also IM 6.9.4.1 is ancient.

Re: How to know the image's transparent space?

Posted: 2019-07-02T09:00:30-07:00
by niyanwen
got it, start a new post, thank you!

Re: How to know the image's transparent space?

Posted: 2019-07-02T14:22:36-07:00
by niyanwen
Hi,

when I used this command to trim the white space, if get output like 0x0+4500+5400, can I assume it is a fully transparent image when I use IM6? for the other method to take care of this is a bit slow, I want to combine to see if I can tell from this command
convert SHIRT_ART_IMAGE1.png -format "%@" +write info: -trim +repage -bordercolor none -border 5 SHIRT_ART_IMAGE1_trim.png

Re: How to know the image's transparent space?

Posted: 2019-07-02T14:23:30-07:00
by niyanwen
basically if output coordinates is 0x0 I mean, can I assume it is a fully transparent image?

Re: How to know the image's transparent space?

Posted: 2019-07-02T14:34:09-07:00
by fmw42
Probably. But to test if an image is fully transparent, the best command would be

convert image.png -channel a -format "%[fx:mean]" info:

If 0, then fully transparent.

Re: How to know the image's transparent space?

Posted: 2019-07-02T14:35:27-07:00
by niyanwen
Yeah, but it takes too much time looks like, after getting rid of this command, time is durable now

Re: How to know the image's transparent space?

Posted: 2019-07-02T14:36:23-07:00
by snibgo
niyanwen wrote:basically if output coordinates is 0x0 I mean, can I assume it is a fully transparent image?
"-format %@" gives 0x0 when all the pixels are the same. They might all be transparent, or all be opaque Red, or opaque White, or anything else.