开发者

How to get 8 bit gray and alpha channel depths with ImageMagick?

I'm trying to create a transparent PNG with ImageMagick. No matter the incantations to "convert", when I use identify against the image, it always says:

Depth: 8/1 bit
Channel depth:
  gray: 1 bit
  alpha: 1 bit

When I look at a transparent PNG found on the web, it says:

Depth: 8 bit
  gray: 8 bit
  alpha: 8 bit

The reason this seems to matter is that I'm using the transparent PNGs I create as a watermark within FFMPEG开发者_如何学Python. When I use the PNG that ImageMagick creates, it causes the video to appear to have like a 50% gray opacity. However, when I use the PNG I found on the web, it works fine. According to identify, the only difference is the depth.

Here are some of the things I've tried:

convert -size 640x480 xc:none -depth 8 test.png
convert -size 640x480 xc:transparent -depth 8 test.png

The other thing I noticed is that Gimp shows the ImageMagick image to have a Colorspace of Grayscale, even though identify says it's RGB. The image that I found on the web, that works, shows a Colorspace of RGB in both Gimp and identify.

Any ideas?


First, about ImageMagick's 'grayscale'.

ImageMagick doesn't actually have such a colorspace. It only fakes it within RGB space, by setting all values in the R (red), G (green) and B (blue) channels to the same values. (If the three values are not the same, the image is no longer grayscale.)


Second, about your (seemingly) unsuccessful attempts to create images with 8-bit alpha channel.

This is caused by you not putting any different 'color' values into your transparent areas -- they are all plain (fully transparent).

Try this command which converts the built-in ImageMagick logo: picture:

convert              \
   logo:             \
  -bordercolor white \
  -background black  \
  +polaroid          \
   polaroid.png

The output image:

How to get 8 bit gray and alpha channel depths with ImageMagick?

will happily show your required 8-bit alpha values:

identify -verbose polaroid.png | grep -A 4 "Channel depth:"

  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
    alpha: 8-bit

Or try to convert the built-in rose: image to a semi-transparent one:

convert  rose:  -alpha set  -channel A  -fx '0.5'  semitransp-rose.png

Same result: 8-bit depth for alpha channel.

To modify one of your original commands:

convert  -size 640x480  xc:none  -depth 8  -channel A -fx 0.5  test.png

If you identify -verbose the resulting image, you'll find the R, G and B channels to be only 1-bit depth, while the A channel is 8-bit. That's because it's actually using a value different from 0, while the other channels are all 0.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜