PDF to PNG - Depth vs Channel depth and Colorspace vs Type
Posted: 2019-05-05T23:14:29-07:00
Please note - for all below examples, I'm using Version: ImageMagick 7.0.8-40 Q16 x64 2019-04-13
When I convert testpdf_grays.pdf to png:
i.) If I use the following command, the resulting PNG is saved as "Grayscale".
magick convert -density 72 "testpdf_grays.pdf" -background white -flatten testpdf_grays.png
I get the warning: convert: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG `testpdf_grays.png' @ warning/png.c/MagickPNGWarningHandler/1747
Ii.) If I use the following command, the resulting PNG is "Colorspace: sRGB" and Type:"Grayscale"
magick convert -density 72 "testpdf_grays.pdf" -background white -flatten PNG24:testpdf_grays24.png
iii.) If I use the following command to create a PNG that's "Colorspace: sRGB" and "Type: GrayscaleAlpha"
magick convert -density 72 "testpdf_grays.pdf" -background white -flatten PNG32:testpdf_grays32.png
The overall "depth" settings in PNG are:
Depth: 8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Alpha: 1-bit
However, PDF is:
Depth: 16/8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Alpha: 8-bit
Iv.) If I use the following command to create a PNG that's "Colorspace sRGB and "Type: GrayscaleAlpha":
magick convert -density 72 "testpdf_grays.pdf" -background white -flatten PNG64:testpdf_grays64.png
The overall "depth" settings in PNG are:
Depth: 16-bit
Channel depth:
Red: 16-bit
Green: 16-bit
Blue: 16-bit
Alpha: 1-bit
However, PDF is:
Depth: 16/8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Alpha: 8-bit
Furthermore - if I do an RGB sampling of the "Top Secret" gray text on the image, it is "203,203,203" in this one image (testpdf_grays64.png), but "202,202,202" in all other versions mentioned above (pdf and pngs).
Question 1: Why is the RGB value changing on the PNG64 iteration?
Question 2: Is it possible to convert the "testpdf_grays.pdf" PDF to a PNG that has bit depths that match the PDF? That is, as follows:
Depth: 16/8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Alpha: 8-bit
Question 3: Is the command I'm using to generate the png32 PNG "good enough" to match original PDF?
magick convert -density 72 "testpdf_grays.pdf" -background white -flatten PNG32:testpdf_grays32.png? The resulting PNG has depths:
Depth: 8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Alpha: 1-bit
Ultimately, I need to ensure that what's "converted" to PNG is as accurate as possible, in regards to "color", and most importantly, "brightness" / "lightness", as the original PDF. The sample PDF appears "gray", however, it's sRGB, and need to account for PDFs that actually have color (for example, testpdf_colors.pdf). And perhaps PNG isn't the best destination format for such a task - if anyone has recommendations re better destination format, then I'm all ears.
All files mentioned above can be found here - along with identify -verbose output.
https://www.dropbox.com/sh/b8ntq5eydy3s ... KlYYa?dl=0
(some of the png files don't look correct when rendering via browser window - not sure why that is. If one downloads a file, and then views, it looks alright. Not too concerned about this.)
[edited to include version]
When I convert testpdf_grays.pdf to png:
i.) If I use the following command, the resulting PNG is saved as "Grayscale".
magick convert -density 72 "testpdf_grays.pdf" -background white -flatten testpdf_grays.png
I get the warning: convert: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG `testpdf_grays.png' @ warning/png.c/MagickPNGWarningHandler/1747
Ii.) If I use the following command, the resulting PNG is "Colorspace: sRGB" and Type:"Grayscale"
magick convert -density 72 "testpdf_grays.pdf" -background white -flatten PNG24:testpdf_grays24.png
iii.) If I use the following command to create a PNG that's "Colorspace: sRGB" and "Type: GrayscaleAlpha"
magick convert -density 72 "testpdf_grays.pdf" -background white -flatten PNG32:testpdf_grays32.png
The overall "depth" settings in PNG are:
Depth: 8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Alpha: 1-bit
However, PDF is:
Depth: 16/8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Alpha: 8-bit
Iv.) If I use the following command to create a PNG that's "Colorspace sRGB and "Type: GrayscaleAlpha":
magick convert -density 72 "testpdf_grays.pdf" -background white -flatten PNG64:testpdf_grays64.png
The overall "depth" settings in PNG are:
Depth: 16-bit
Channel depth:
Red: 16-bit
Green: 16-bit
Blue: 16-bit
Alpha: 1-bit
However, PDF is:
Depth: 16/8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Alpha: 8-bit
Furthermore - if I do an RGB sampling of the "Top Secret" gray text on the image, it is "203,203,203" in this one image (testpdf_grays64.png), but "202,202,202" in all other versions mentioned above (pdf and pngs).
Question 1: Why is the RGB value changing on the PNG64 iteration?
Question 2: Is it possible to convert the "testpdf_grays.pdf" PDF to a PNG that has bit depths that match the PDF? That is, as follows:
Depth: 16/8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Alpha: 8-bit
Question 3: Is the command I'm using to generate the png32 PNG "good enough" to match original PDF?
magick convert -density 72 "testpdf_grays.pdf" -background white -flatten PNG32:testpdf_grays32.png? The resulting PNG has depths:
Depth: 8-bit
Channel depth:
Red: 8-bit
Green: 8-bit
Blue: 8-bit
Alpha: 1-bit
Ultimately, I need to ensure that what's "converted" to PNG is as accurate as possible, in regards to "color", and most importantly, "brightness" / "lightness", as the original PDF. The sample PDF appears "gray", however, it's sRGB, and need to account for PDFs that actually have color (for example, testpdf_colors.pdf). And perhaps PNG isn't the best destination format for such a task - if anyone has recommendations re better destination format, then I'm all ears.
All files mentioned above can be found here - along with identify -verbose output.
https://www.dropbox.com/sh/b8ntq5eydy3s ... KlYYa?dl=0
(some of the png files don't look correct when rendering via browser window - not sure why that is. If one downloads a file, and then views, it looks alright. Not too concerned about this.)
[edited to include version]