23

I use Imagemagick convert to convert pdf file to png as follows:

Magick convert -density 300 PointOnLine.pdf -quality 90 PointOnLine.png

It gives warning:

convert: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG `PointOnLine.png' @ warning/png.c/MagickPNGWarningHandler/1744.

And png image created is all black. However, convert to jpg image is fine. What is the problem? Thanks.

3 Answers 3

22

Try adding -colorspace RGB before the outfile name.

convert -density 300 PointOnLine.pdf -quality 90 -colorspace RGB PointOnLine.png
2
  • Nice. For me the white background became transparent, but this can still be used.
    – user74094
    Commented Mar 25, 2020 at 14:46
  • Note that this solution, although removing the warning, also changes the shades of gray in the generated PNG.
    – DannyB
    Commented Dec 22, 2020 at 9:52
10

The documentation says this:

PNG RW Portable Network Graphics Requires libpng-1.0.11 or later, libpng-1.2.5 or later recommended. The PNG specification does not support pixels-per-inch units, only pixels-per-centimeter. To avoid reading a particular associated image profile, use -define profile:skip=name (e.g. profile:skip=ICC).

So try adding -define profile:skip=ICC (or skip="*") before the outfile name.

See also: documentation on the define command

3
  • 1
    No, after setting -define profile:skip=ICC, image is still dark. But if convert to jpg and then to png, it is ok, but background is dark. The same warning happens.
    – E Zhang
    Commented Feb 7, 2018 at 18:19
  • This works better than setting -colorspace RGB - for me it removes the warning and does not alter the shades of gray of the output.
    – DannyB
    Commented Dec 22, 2020 at 9:53
  • I don’t want to put the validity of this answer in question but I just don’t understand the connection between “pixels per centimetre/inch” and a colour profile. Can somebody explain this to me? Commented Jul 22, 2021 at 11:25
2

I'm using ImageMagick 7.1.1-8 and just had the same issue:

$ magick example.pdf output.png
magick: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG `output.png' @ warning/png.c/MagickPNGWarningHandler/1526.
$ magick -version
Version: ImageMagick 7.1.1-8 Q16-HDRI x86_64 d92cb0e65:20230421 https://imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5) 
Delegates (built-in): bzlib djvu fontconfig freetype heic jbig jng jpeg lcms lqr lzma openexr png raqm tiff webp x xml zlib
Compiler: gcc (7.5)
$ 

In my case, ImageMagick (using Ghostscript) is reading my input PDF file and produces image data in sRGB colorspace with an embedded ICC profile:

$ magick example.pdf -verbose info: | grep "Colorspace:"
  Colorspace: sRGB
$ magick example.pdf -verbose info: | grep -A1 "Profiles:"
  Profiles:
    Profile-icc: 2576 bytes
$ 

When saving that image data as a PNG file, ImageMagick automatically optimizes the colorspace and saves the file as a grayscale PNG with color type 0:

$ magick output.png -verbose info: | grep "Colorspace:"
  Colorspace: Gray
$ magick output.png -verbose info: | grep "color_type"
    png:IHDR.color_type: 0 (Grayscale)
$ 

But it does not remove the embedded ICC profile:

$ magick output.png -verbose info: | grep -A1 "Profiles:"
  Profiles:
    Profile-icc: 2576 bytes
$ 

That's what the warning is about: libpng is not expecting a color ICC profile embedded in a grayscale PNG.

To get rid of the warning, we can either

  1. keep the ICC profile but hide warnings in general,
  2. remove the ICC profile or
  3. keep the ICC profile and save not as a grayscale PNG.

Keep the ICC profile but hide warnings in general

If you want to simply hide the warning, use the -quiet option. After all, it's not an error, but only a warning:

$ magick example.pdf -quiet output.png
$ 

A downside might be that if other warnings show up in the future, you won't notice because you are already hiding them, too.

Remove the ICC profile

Instead, you can choose to remove the ICC profile. There's multiple ways to do so. Other answers mention changing the colorspace, for example. This (sometimes) works, because ImageMagick automatically removes embedded profiles when changing the colorspace:

(void) DeleteImageProfile(image,"icc");
(void) DeleteImageProfile(image,"icm");

Source: https://github.com/ImageMagick/ImageMagick/blob/7a63f554dc0f986aa3ef2767d041a0f3294decd2/MagickCore/colorspace.c#L1624-L1625

There's two disadvantages to this approach:

  1. If your image is already in colorspace sRGB and you use -colorspace sRGB to convert to colorspace sRGB, ImageMagick ignores the operator and therefore the profile will not get removed. For example, my input PDF file produced an image in sRGB colorspace which means -colorspace sRGB has no effect and does not remove the profile:

    $ magick example.pdf -colorspace sRGB -verbose info: | grep -A1 "Profiles:"
      Profiles:
        Profile-icc: 2576 bytes
    $ 
    

    Conversely, the same is true if you use -colorspace RGB on an image that is already in RGB colorspace. So if you want to use this method to remove the ICC profile, you would have to check in advance if your image is in sRGB or RGB and then use -colorspace accordingly.

  2. Obviously, if you use -colorspace to change the colorspace of your image, the colors of your image might change which makes the image look different. Therefore, after converting the colorspace to a different colorspace to remove the profile, you should convert the colorspace back to the original colorspace. So your command will use the -colorspace operator twice. For my example file, which is sRGB, I convert to RGB first, then back to sRGB:

    $ magick example.pdf -colorspace RGB -colorspace sRGB -verbose info: | grep "Colorspace:"
      Colorspace: sRGB
    $ magick example.pdf -colorspace RGB -colorspace sRGB -verbose info: | grep -A1 "Profiles:"
    $ 
    

    You will probably still get some rounding errors from the conversions, but the image will more or less look identical.

An alternative way to remove the profile is to simply use -strip:

$ magick example.pdf -strip -verbose info: | grep -A1 "Profiles:"
$ 

However, that option not only removes all profiles but also further metadata, which might not be desired behavior. See https://imagemagick.org/script/command-line-options.php#strip for more information.

To specifically remove the ICC profile from the image before saving, you can use +profile icc:

$ magick example.pdf +profile icc -verbose info: | grep -A1 "Profiles:"
$ 

Alternatively, to specifically not read any ICC profile from the input file in the first place, you can use -define profile:skip=icc:

$ magick -define profile:skip=icc example.pdf -verbose info: | grep -A1 "Profiles:"
$ 

Note that this setting affects reading, so you have to put it before your input file.

Keep the ICC profile and save not as a grayscale PNG

Finally, if you want to keep the profile, you can use -define png:color-type= to set your desired PNG color type to avoid automatic conversion to grayscale and therefore to avoid the warning. For my example file, I might want "Truecolour with alpha" which is color type 6:

$ magick example.pdf -define png:color-type=6 output.png
$ magick output.png -verbose info: | grep "color_type"
    png:IHDR.color_type: 6 (RGBA)
$

Alternatively, you can use for example the PNG32: output prefix:

$ magick example.pdf PNG32:output.png
$ magick output.png -verbose info: | grep "color_type"
    png:IHDR.color_type: 6 (RGBA)
$ 

In both cases, no warning shows up, yet the ICC profile is retained:

$ magick output.png -verbose info: | grep -A1 "Profiles:"
  Profiles:
    Profile-icc: 2576 bytes
$ 

You can read further about this issue at ImageMagick's GitHub Discussions page at https://github.com/ImageMagick/ImageMagick/discussions/2730 and https://github.com/ImageMagick/ImageMagick/discussions/6292 which provides excellent support.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .