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 !
transparent background will be truned into black with grayscaling
-
- Posts: 16
- Joined: 2015-07-31T12:35:27-07:00
- Authentication code: 1151
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: transparent background will be truned into black with grayscaling
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.
-
- Posts: 16
- Joined: 2015-07-31T12:35:27-07:00
- Authentication code: 1151
Re: transparent background will be truned into black with grayscaling
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: transparent background will be truned into black with grayscaling
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
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
-
- Posts: 16
- Joined: 2015-07-31T12:35:27-07:00
- Authentication code: 1151
Re: transparent background will be truned into black with grayscaling
Hi,
Thanks! My python code is like this:
When I do identify I get this:
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")
What does that mean?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
-
- Posts: 16
- Joined: 2015-07-31T12:35:27-07:00
- Authentication code: 1151
Re: transparent background will be truned into black with grayscaling
I got it !
I think you were right, it has to be 'grayscalematte' instead of 'grayscale'
I think you were right, it has to be 'grayscalematte' instead of 'grayscale'