Page 1 of 1

Check if Corners are transparent

Posted: 2009-06-01T23:06:04-07:00
by gotskill10
How would I check if an Image has atleast one corner pixel that is transparent?

Re: Check if Corners are transparent

Posted: 2009-06-02T10:39:30-07:00
by fmw42
gotskill10 wrote:How would I check if an Image has atleast one corner pixel that is transparent?
convert each of the four corner pixels, one at a time to txt: format and look at the information

Make test image as gradient with left half transparent and right half opaque:
convert -size 100x100 gradient: -rotate 90 grad100.png
freds-mac-mini:~ fred$ convert grad100.png -threshold 50% grad100t50.png
freds-mac-mini:~ fred$ convert grad100.png grad100t50.png -compose copy_opacity -composite grad100_at50.png

convert grad100_at50.png[1x1+0+0] txt:-
# ImageMagick pixel enumeration: 1,1,65535,rgba
0,0: ( 0, 0, 0, 0) #000000000000000 none

So the above is transparent:


convert grad100_at50.png[1x1+99+99] txt:-
# ImageMagick pixel enumeration: 1,1,65535,rgba
0,0: (65535,65535,65535,65535) #FFFFFFFFFFFF white

So the above is opaque

Re: Check if Corners are transparent

Posted: 2009-06-02T21:42:08-07:00
by anthony
Their was also a post recently about extracting the colors of the four corners, this may provide a better check. For example.

Code: Select all

convert grad100_at50.png -roll +1+1 -crop 2x2+0+0 +repage txt:
produces
# ImageMagick pixel enumeration: 2,2,65535,rgba
0,0: (65535,65535,65535,65535) #FFFFFFFFFFFF white
1,0: ( 0, 0, 0, 0) #0000000000000000 none
0,1: (65535,65535,65535,65535) #FFFFFFFFFFFF white
1,1: ( 0, 0, 0, 0) #0000000000000000 none
or two corners are white and two are transparent.

Re: Check if Corners are transparent

Posted: 2009-06-02T22:10:49-07:00
by fmw42
convert grad100_at50.png -roll +1+1 -crop 2x2+0+0 +repage txt:
neat way to get only the 4 corners

Re: Check if Corners are transparent

Posted: 2009-06-03T00:10:40-07:00
by anthony
And by using -roll you avoid needing to know the size of the image ;-)