How to get 8-bit gray and alpha channels using ImageMagick?

I am trying to create a transparent PNG with ImageMagick. Regardless of the โ€œconvertโ€ spell, when I use identification against the image, it always says:

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

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

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

The reason this matters is because I use transparent PNGs, which I create as a watermark inside FFMPEG. When I use PNG, which ImageMagick creates, it makes the video look like 50% gray opacity. However, when I use PNG, which I found on the Internet, it works fine. According to the identification, 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 

Another thing I noticed is that Gimp shows an ImageMagick image in order to have Colorspace Grayscale, although the identifier says this is RGB. The image I found on the Internet that works shows Colorspace RGB in both Gimp and identifies.

Any ideas?

+4
source share
1 answer

First, about the grayscale ImageMagick.

ImageMagick does not actually have that color space. This only fakes it in the RGB space, setting all the values โ€‹โ€‹in the R (red), G (green) and B (blue) channels to the same values. (If the three values โ€‹โ€‹do not match, the image will no longer be displayed in grayscale.)


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

This is because you do not put different color values โ€‹โ€‹in your transparent areas, they are all simple (completely transparent).

Try this command, which converts the embedded image ImageMagick logo: ::

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

Output Image:

Polaroid effect by 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 converting the inline rose: image to translucent:

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

Same result: 8-bit depth for alpha channel.

To change one of the source commands:

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

If you identify -verbose resulting image, you will see that the channels R, G and B are only 1-bit deep and channel A is 8 bits. This is because a value other than 0 is actually used, while the rest of the channels are all 0 .

+1
source

All Articles