Page 1 of 1

transparent background will be truned into black with grayscaling

Posted: 2015-07-31T14:19:42-07:00
by baxter stockman
Hi,

I am using Wand in python and try to grayscale it, however, every png with a transparent background will get turned into a black one. How do I avoid this?

I am using the colorspace method for that for that from the documentation here https://media.readthedocs.org/pdf/wand/ ... e/wand.pdf .

THanks !

Re: transparent background will be truned into black with grayscaling

Posted: 2015-07-31T15:58:54-07:00
by fmw42
I cannot answer this question, but it would help some one who could if you provide your IM version and platform and what file type you are saving to. If JPG, it does not support transparency.

Re: transparent background will be truned into black with grayscaling

Posted: 2015-08-03T16:07:55-07:00
by baxter stockman
Hi,

I am trying to save a PNG. My version is imageMagick 6.7.7.10

I am using it with python in ubuntu and right now I am just changing the saturation via img.modulate(saturation=0.0)

I found somewhere that I could use:

img.alpha = True
# or
img.background_color = Color('transparent')

However both of these don't do anything.

Any advice? Thanks in advance

Re: transparent background will be truned into black with grayscaling

Posted: 2015-08-03T16:31:10-07:00
by fmw42
I do not know the MagickWand API. But perhaps if you post your your code, someone who knows it may be able to comment.

Is your PNG 32 bits or 8 bits pseudocolor? Perhaps if the latter, the transparent color is getting overlooked by converting to grayscale, since the grayscale color used for transparency may not be a grayshade.. Try converting your PNG to 32 bit color first so it is using a true alpha channel.

What do you get from:

identify -verbose your_input_image.png

Re: transparent background will be truned into black with grayscaling

Posted: 2015-08-23T14:16:15-07:00
by baxter stockman
Hi,

Thanks! My python code is like this:

Code: Select all

def grey():
        with Image (filename="image7.png") as img:
            img.type='grayscale';
            img.save(filename="image7_grey.png")
When I do identify I get this:
Image: image7.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 799x168+0+0
Resolution: 72x72
Print size: 11.0972x2.33333
Units: Undefined
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 8-bit
Channel statistics:
Red:
min: 0 (0)
max: 255 (1)
mean: 41.6259 (0.163239)
standard deviation: 90.0122 (0.352989)
kurtosis: 0.892462
skewness: 1.70038
Green:
min: 0 (0)
max: 51 (0.2)
mean: 4.71354 (0.0184845)
standard deviation: 10.2868 (0.0403404)
kurtosis: 1.0775
skewness: 1.73794
Blue:
min: 0 (0)
max: 64 (0.25098)
mean: 6.28679 (0.0246541)
standard deviation: 13.698 (0.0537178)
kurtosis: 1.02764
skewness: 1.72916
Alpha:
min: 0 (0)
max: 255 (1)
mean: 39.5321 (0.155028)
standard deviation: 90.1361 (0.353475)
kurtosis: 1.69553
skewness: -1.90412
Image statistics:
Overall:
min: 0 (0)
max: 255 (1)
mean: 67.0235 (0.262837)
standard deviation: 64.2654 (0.252021)
kurtosis: 15.1297
skewness: 5.26295
Alpha: none #00000000
Colors: 259
What does that mean?

Re: transparent background will be truned into black with grayscaling

Posted: 2015-08-23T14:38:27-07:00
by baxter stockman
I got it !

I think you were right, it has to be 'grayscalematte' instead of 'grayscale'