Determine if Alpha Channel is Used in an Image

前端 未结 7 1909
北恋
北恋 2020-12-06 05:29

As I\'m bringing in images into my program, I want to determine if:

  1. they have an alpha-channel
  2. if that alpha-channel is used

#1

7条回答
  •  一整个雨季
    2020-12-06 06:05

    The simplest method using ImageMagick (command line) is to test the alpha channel if the mean is less than 1 (on a scale of 0 to 1). 1 is fully opaque. So

    convert image -channel a -separate -format "%[fx:(mean<1)?1:0]" info:
    

    If the return value is 1, then at least one pixel is transparent; otherwise (if 0), the image is fully opaque.

提交回复
热议问题