Check if Corners are transparent
-
- Posts: 17
- Joined: 2007-06-02T14:01:34-07:00
Check if Corners are transparent
How would I check if an Image has atleast one corner pixel that is transparent?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Check if Corners are transparent
convert each of the four corner pixels, one at a time to txt: format and look at the informationgotskill10 wrote:How would I check if an Image has atleast one corner pixel that is transparent?
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
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Check if Corners are transparent
Their was also a post recently about extracting the colors of the four corners, this may provide a better check. For example.
produces
Code: Select all
convert grad100_at50.png -roll +1+1 -crop 2x2+0+0 +repage txt:
or two corners are white and two are transparent.# 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Check if Corners are transparent
neat way to get only the 4 cornersconvert grad100_at50.png -roll +1+1 -crop 2x2+0+0 +repage txt:
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Check if Corners are transparent
And by using -roll you avoid needing to know the size of the image
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/