Trouble forcing TrueColorMatte
Trouble forcing TrueColorMatte
I can't seem to be able to convert a transparent image that only contains grayscale elements and force it to be TrueColorMatte.
I have tried:
convert test.svg -type TrueColorMatte test.png
but the type of the PNG is GrayscaleMatte.
Even if I do a mogrify on the resulting PNG:
mogrify -type TrueColorMatte test.png
I still end up with type: GrayscaleMatte
I know that GrayscaleMatte results in a smaller file size, but GD doesn't support transparency in Grayscale images and I use TCPDF (which uses GD) to create a contact sheet of transparent PNGs.
Thanks,
Adrian
I have tried:
convert test.svg -type TrueColorMatte test.png
but the type of the PNG is GrayscaleMatte.
Even if I do a mogrify on the resulting PNG:
mogrify -type TrueColorMatte test.png
I still end up with type: GrayscaleMatte
I know that GrayscaleMatte results in a smaller file size, but GD doesn't support transparency in Grayscale images and I use TCPDF (which uses GD) to create a contact sheet of transparent PNGs.
Thanks,
Adrian
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Trouble forcing TrueColorMatte
best I can suggest is insert one colored pixel say in the top left corner
Re: Trouble forcing TrueColorMatte
Thanks for the suggestion - is there really no way to force it otherwise? Is this a limitation of imagemagick, or image formats in general?
I have actually just found that if I ensure that the colormode of the original SVG is RGB and not CMYK (when saving it from Illustrator), then imagemagick creates a transparent PNG which is TrueColorMatte. What is confusing is that whether the original SVG is RGB or CMYK, the original SVG and the converted PNG are still listed as having an RGB Colorspace. The only difference I can see when creating the SVG (via Illustrator's Save for Web) is that CMYK color mode results in "Bilevel", whereas RGB color mode results in "TrueColorMatte".
Would be great if Imagemagick could convert the Bilevel SVG to a TrueColorMatte PNG, but at least I have a workaround for now - I just need to make sure that users uploading ensure they are in RGB mode - not an ideal situation.
Thanks,
Adrian
I have actually just found that if I ensure that the colormode of the original SVG is RGB and not CMYK (when saving it from Illustrator), then imagemagick creates a transparent PNG which is TrueColorMatte. What is confusing is that whether the original SVG is RGB or CMYK, the original SVG and the converted PNG are still listed as having an RGB Colorspace. The only difference I can see when creating the SVG (via Illustrator's Save for Web) is that CMYK color mode results in "Bilevel", whereas RGB color mode results in "TrueColorMatte".
Would be great if Imagemagick could convert the Bilevel SVG to a TrueColorMatte PNG, but at least I have a workaround for now - I just need to make sure that users uploading ensure they are in RGB mode - not an ideal situation.
Thanks,
Adrian
Re: Trouble forcing TrueColorMatte
Thanks for the link. I have been trying many combinations and still not quite getting what I want.
This is the latest version I am trying. It results in a transparent PNG, but the Type is "Bilevel" and not "TrueColorMatte"
convert -background transparent cmyk_image.svg -format PNG32 -type truecolormatte -colorspace RGB -define png:color-type=6 -define png:bit-depth=8 cmyk_image.png
Any suggestions on where I am going wrong?
Thanks
This is the latest version I am trying. It results in a transparent PNG, but the Type is "Bilevel" and not "TrueColorMatte"
convert -background transparent cmyk_image.svg -format PNG32 -type truecolormatte -colorspace RGB -define png:color-type=6 -define png:bit-depth=8 cmyk_image.png
Any suggestions on where I am going wrong?
Thanks
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Trouble forcing TrueColorMatte
the comment in the link to the other forum by Magick says that IM identify will not see the true type. you need to use pngcheck. I don't understand it and have not had time to get or use pngcheck to see what he is saying about it. but look again at his comments.
Re: Trouble forcing TrueColorMatte
Well it turns out that the only way I can achieve what I want - ie get and SVG and the resulting PNG to be TrueColorMatte is to make sure that there is at least some color in the original SVG. The only way I could figure out how to do this was to manipulate the SVG itself before imagemagick does anything.
I came up with this:
It's not perfect because it doesn't change anything but black - it really also needs to convert all grays.
I also discovered that so long as you make sure that the SVG is saved from Illustrator when it has an RGB Document Color Mode, then this isn't needed, because #000000's get converted to #231F20 by default when it is saved.
I came up with this:
Code: Select all
$black_replacement = '#231F20';
$objDOM = new DOMDocument();
$objDOM->load($path_to_image);
$svgtags = array('polygon','polyline','rect','circle','ellipse','line','path');
foreach($svgtags as $svgtag){
$tags = $objDOM->getElementsByTagName($svgtag);
foreach($tags as $tag){
if($tag->hasAttribute('fill')){
if($tag->getAttribute('fill') == '#000000' || $tag->getAttribute('fill') == 'black'){
$tag->setAttribute('fill', $black_replacement);
}
}
else{
$tag->setAttribute('fill', $black_replacement);
}
if($tag->hasAttribute('stroke')){
if($tag->getAttribute('stroke') == '#000000' || $tag->getAttribute('stroke') == 'black'){
$tag->setAttribute('stroke', $black_replacement);
}
}
}
}
I also discovered that so long as you make sure that the SVG is saved from Illustrator when it has an RGB Document Color Mode, then this isn't needed, because #000000's get converted to #231F20 by default when it is saved.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Trouble forcing TrueColorMatte
see the discussion at viewtopic.php?f=3&t=15445
Re: Trouble forcing TrueColorMatte
Well finally sorted without needing to modify the SVG.
I did go through the other post you highlighted and I had tried pngcheck before and also identify with -debug coder -log %e
Before both seemed to show GrayScale or Bilevel. I updated to 6.5.9-1 and now pngcheck -v shows 32-bit RGB+alpha which is what I want, although identify -debug coder -log %e still shows BiLevel. This doesn't me, because now the image is actually compatible with GD, which was my main concern from the beginning.
For the record, this is the command that worked for me:
convert -background transparent cmyk_spiderweb.svg -format png32 -depth 8 -type TruecolorMatte -define png:color-type=6 cmyk_spiderweb.png
and the order of commands does seem quite important.
Thanks for the help!
I did go through the other post you highlighted and I had tried pngcheck before and also identify with -debug coder -log %e
Before both seemed to show GrayScale or Bilevel. I updated to 6.5.9-1 and now pngcheck -v shows 32-bit RGB+alpha which is what I want, although identify -debug coder -log %e still shows BiLevel. This doesn't me, because now the image is actually compatible with GD, which was my main concern from the beginning.
For the record, this is the command that worked for me:
convert -background transparent cmyk_spiderweb.svg -format png32 -depth 8 -type TruecolorMatte -define png:color-type=6 cmyk_spiderweb.png
and the order of commands does seem quite important.
Thanks for the help!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Trouble forcing TrueColorMatte
works fine for me:
convert -size 50x50 xc:white -bordercolor black -border 50 square.gif
identify -verbose square.gif
Image: square.gif
Format: GIF (CompuServe graphics interchange format)
Class: PseudoClass
Geometry: 150x150+0+0
Resolution: 72x72
Print size: 2.08333x2.08333
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8/1-bit
Channel depth:
gray: 1-bit
convert square.gif -transparent black -depth 8 -type TruecolorMatte -define png:color-type=6 PNG32:square31t.png
identify -verbose square31t.png
Image: square31t.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 150x150+0+0
Resolution: 72x72
Print size: 2.08333x2.08333
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8/1-bit
Channel depth:
gray: 1-bit
alpha: 1-bit
identify will still say bilevel as has been explained, but using -debug coder says it is really type=6 and does not say anything about it being bilevel
identify -debug coder -log %e square31t.png
enter ReadPNGImage()
enter ReadOnePNGImage()
PNG width: 150, height: 150
PNG color_type: 6, bit_depth: 8
PNG compression_method: 0
PNG interlace_method: 0, filter_method: 0
Reading PNG pHYs chunk: xres: 72, yres: 72, units: 0.
Reading PNG bKGD chunk.
Reading PNG IDAT chunk(s)
Converting PNG pixels to pixel packets
Reading PNG text chunk
Keyword: date:create
Reading PNG text chunk
Keyword: date:modify
exit ReadOnePNGImage()
exit ReadPNGImage()
square31t.png PNG 150x150 150x150+0+0 8-bit DirectClass 443b 0.020u 0:00.040
convert -size 50x50 xc:white -bordercolor black -border 50 square.gif
identify -verbose square.gif
Image: square.gif
Format: GIF (CompuServe graphics interchange format)
Class: PseudoClass
Geometry: 150x150+0+0
Resolution: 72x72
Print size: 2.08333x2.08333
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8/1-bit
Channel depth:
gray: 1-bit
convert square.gif -transparent black -depth 8 -type TruecolorMatte -define png:color-type=6 PNG32:square31t.png
identify -verbose square31t.png
Image: square31t.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 150x150+0+0
Resolution: 72x72
Print size: 2.08333x2.08333
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8/1-bit
Channel depth:
gray: 1-bit
alpha: 1-bit
identify will still say bilevel as has been explained, but using -debug coder says it is really type=6 and does not say anything about it being bilevel
identify -debug coder -log %e square31t.png
enter ReadPNGImage()
enter ReadOnePNGImage()
PNG width: 150, height: 150
PNG color_type: 6, bit_depth: 8
PNG compression_method: 0
PNG interlace_method: 0, filter_method: 0
Reading PNG pHYs chunk: xres: 72, yres: 72, units: 0.
Reading PNG bKGD chunk.
Reading PNG IDAT chunk(s)
Converting PNG pixels to pixel packets
Reading PNG text chunk
Keyword: date:create
Reading PNG text chunk
Keyword: date:modify
exit ReadOnePNGImage()
exit ReadPNGImage()
square31t.png PNG 150x150 150x150+0+0 8-bit DirectClass 443b 0.020u 0:00.040
Re: Trouble forcing TrueColorMatte
Here is my output:
As you can see, pngcheck seems right, but identify -debug still shows BiLevel. It does also now show PNG color_type: 6, bit_depth: 8, so maybe that is all I should be worried about.
pngcheck -v test.png
File: normal_cmyk_spiderweb.png (35462 bytes)
chunk IHDR at offset 0x0000c, length 13
316 x 400 image, 32-bit RGB+alpha, non-interlaced
chunk bKGD at offset 0x00025, length 6
red = 0x0000, green = 0x0000, blue = 0x0000
chunk pHYs at offset 0x00037, length 9: 72x72 pixels/unit
chunk vpAg at offset 0x0004c, length 9
unknown private, ancillary, safe-to-copy chunk
chunk IDAT at offset 0x00061, length 32768
zlib: deflated, 32K window, maximum compression
chunk IDAT at offset 0x0806d, length 2415
chunk tEXt at offset 0x089e8, length 37, keyword: date:create
chunk tEXt at offset 0x08a19, length 37, keyword: date:modify
chunk tEXt at offset 0x08a4a, length 40, keyword: svg:base-uri
chunk IEND at offset 0x08a7e, length 0
No errors detected in normal_cmyk_spiderweb.png (10 chunks, 93.0% compression).
identify -verbose -debug coder -log %e test.png
enter ReadPNGImage()
enter ReadOnePNGImage()
PNG width: 316, height: 400
PNG color_type: 6, bit_depth: 8
PNG compression_method: 0
PNG interlace_method: 0, filter_method: 0
Reading PNG pHYs chunk: xres: 72, yres: 72, units: 0.
Reading PNG bKGD chunk.
Reading PNG IDAT chunk(s)
Converting PNG pixels to pixel packets
Reading PNG text chunk
Keyword: date:create
Reading PNG text chunk
Keyword: date:modify
Reading PNG text chunk
Keyword: svg:base-uri
exit ReadOnePNGImage()
exit ReadPNGImage()
Image: normal_cmyk_spiderweb.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 316x400+0+0
Resolution: 72x72
Print size: 4.38889x5.55556
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 1-bit
alpha: 8-bit
Channel statistics:
Gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
Alpha:
min: 255 (1)
max: 0 (0)
mean: 26.4876 (0.103873)
standard deviation: 72.9036 (0.285896)
kurtosis: 4.89782
skewness: -2.57885
Alpha: none #00000000
identify -verbose test.png
Image: normal_cmyk_spiderweb.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 316x400+0+0
Resolution: 72x72
Print size: 4.38889x5.55556
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 1-bit
alpha: 8-bit
Channel statistics:
Gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
Alpha:
min: 255 (1)
max: 0 (0)
mean: 26.4876 (0.103873)
standard deviation: 72.9036 (0.285896)
kurtosis: 4.89782
skewness: -2.57885
Alpha: none #00000000
As you can see, pngcheck seems right, but identify -debug still shows BiLevel. It does also now show PNG color_type: 6, bit_depth: 8, so maybe that is all I should be worried about.
pngcheck -v test.png
File: normal_cmyk_spiderweb.png (35462 bytes)
chunk IHDR at offset 0x0000c, length 13
316 x 400 image, 32-bit RGB+alpha, non-interlaced
chunk bKGD at offset 0x00025, length 6
red = 0x0000, green = 0x0000, blue = 0x0000
chunk pHYs at offset 0x00037, length 9: 72x72 pixels/unit
chunk vpAg at offset 0x0004c, length 9
unknown private, ancillary, safe-to-copy chunk
chunk IDAT at offset 0x00061, length 32768
zlib: deflated, 32K window, maximum compression
chunk IDAT at offset 0x0806d, length 2415
chunk tEXt at offset 0x089e8, length 37, keyword: date:create
chunk tEXt at offset 0x08a19, length 37, keyword: date:modify
chunk tEXt at offset 0x08a4a, length 40, keyword: svg:base-uri
chunk IEND at offset 0x08a7e, length 0
No errors detected in normal_cmyk_spiderweb.png (10 chunks, 93.0% compression).
identify -verbose -debug coder -log %e test.png
enter ReadPNGImage()
enter ReadOnePNGImage()
PNG width: 316, height: 400
PNG color_type: 6, bit_depth: 8
PNG compression_method: 0
PNG interlace_method: 0, filter_method: 0
Reading PNG pHYs chunk: xres: 72, yres: 72, units: 0.
Reading PNG bKGD chunk.
Reading PNG IDAT chunk(s)
Converting PNG pixels to pixel packets
Reading PNG text chunk
Keyword: date:create
Reading PNG text chunk
Keyword: date:modify
Reading PNG text chunk
Keyword: svg:base-uri
exit ReadOnePNGImage()
exit ReadPNGImage()
Image: normal_cmyk_spiderweb.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 316x400+0+0
Resolution: 72x72
Print size: 4.38889x5.55556
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 1-bit
alpha: 8-bit
Channel statistics:
Gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
Alpha:
min: 255 (1)
max: 0 (0)
mean: 26.4876 (0.103873)
standard deviation: 72.9036 (0.285896)
kurtosis: 4.89782
skewness: -2.57885
Alpha: none #00000000
identify -verbose test.png
Image: normal_cmyk_spiderweb.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 316x400+0+0
Resolution: 72x72
Print size: 4.38889x5.55556
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 8-bit
Channel depth:
gray: 1-bit
alpha: 8-bit
Channel statistics:
Gray:
min: 0 (0)
max: 0 (0)
mean: 0 (0)
standard deviation: 0 (0)
kurtosis: 0
skewness: 0
Alpha:
min: 255 (1)
max: 0 (0)
mean: 26.4876 (0.103873)
standard deviation: 72.9036 (0.285896)
kurtosis: 4.89782
skewness: -2.57885
Alpha: none #00000000
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Trouble forcing TrueColorMatte
the key line is
PNG color_type: 6, bit_depth: 8
which says it is really type=6 or RGBA
leave off the -verbose in your line so it is
identify -debug coder log %e yourimage
then it won't confuse you with the verbose info that will always say bilevel
PNG color_type: 6, bit_depth: 8
which says it is really type=6 or RGBA
leave off the -verbose in your line so it is
identify -debug coder log %e yourimage
then it won't confuse you with the verbose info that will always say bilevel