9

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

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

It gives me the following 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.

Update: After adding -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 is still there. What is the problem? Thanks.

Niall Kiddle
  • 1,477
  • 1
  • 16
  • 35
  • 2
    Maybe you have a *"mad"* PDF. Do you care to share it? – Mark Setchell Feb 05 '18 at 19:39
  • PNG does not like adding a color profile to a grayscale image. It is just a warning and should produce your output. If you do not want to see the warning add -quiet to your Imagemagick command. Note that -quality 90 may not be proper for PNG. PNG does not use the same code for quality as JPG. See https://www.imagemagick.org/script/command-line-options.php#quality – fmw42 Feb 06 '18 at 02:06
  • Are you sure the image is black and not with a transparent background? Try that: `Magick convert -density 300 PointOnLine.pdf -quality 90 -flatten PointOnLine.png` – shadowsheep Feb 14 '18 at 12:04
  • @user585440 the answer with the `flatten` param and the `alpha channel` should be mine, 'cause I ask you much time earlier... but you didn't answer me... – shadowsheep Feb 15 '18 at 08:09
  • @ shadowsheep, you should post your answer –  Feb 15 '18 at 18:03

5 Answers5

4

The following works for me without error in ImageMagick 7.0.7.22 Q16 Mac OSX Sierra with Ghostscript 9.21 and libpng @1.6.34_0. Your PDF has an alpha channel, so you might want to flatten it.

magick -density 300 PointOnLine.pdf -flatten -quality 90 result.png

This also works without error, but leaves the alpha channel in the png, though you won't see it here until you extract the image:

magick -density 300 PointOnLine.pdf -quality 90 result2.png

Note that in IM 7 you should just use magick and not magick convert.

Check that you are using a current version of Ghostscript and libpng, if you do not get the same results.

Your delegates.xml file for PS:alpha should show sDEVICE=pngalpha rather than pnmraw as follows.

<delegate decode="ps:alpha" stealth="True" command="&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pngalpha&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;"/>

USER REQUESTED RESULTING IMAGES THAT I POSTED TO BE REMOVED!

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • It gives "magick: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG `result.png' @ warning/png.c/MagickPNGWarningHandler/1744.". But image is ok. –  Feb 14 '18 at 21:46
  • Without flatten, image background is not white. –  Feb 14 '18 at 21:50
  • I did not get any profile error. I presume it was your version of libpng. Your image has an alpha channel. Without -flatten it will show whatever is in the background of your png as being under the transparency in your png. You can force it to be whatever color you want by including -background somecolor. Is there some reason the images should be removed? They do not seem proprietary. It is bad form to remove posted images. But if you insist, I will remove them. – fmw42 Feb 14 '18 at 22:41
  • Try adding -quiet right after magick in the command line. Does that get rid of the message? – fmw42 Feb 14 '18 at 23:17
2

Command which worked for me was:

magick -density 300 PointOnLine.pdf -depth 8 -strip -background white -alpha off PointOnLine.tiff

It did not gave any warning, also removed black blackground as well.

I was able to convert it to the text afterwards using tesseract:

tesseract PointOnLine.tiff PointOnLine
D555
  • 1,704
  • 6
  • 26
  • 48
  • 1
    This solution worked for me, creating one image per page. The accepted answer flattened all pages of the pdf in a single image. – scharette Sep 18 '19 at 21:05
1

I understand you are using ImageMagick under Windows, even if not stated (and the respective versions of IM, Win were not posted)

I am under Ubuntu 16.04 LTS, and I will provide an answer possibly useful. (Under Win, prepend everything with Magick). For me,

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

works fine, with no warnings, producing a suitable output. I tried other things which work as well, some of them may suit you.

  1. First convert your pdf to RGB and then to png.

    convert -density 300 -colorspace RGB PointOnLine.pdf PointOnLine_rgb.pdf
    convert -density 300 PointOnLine_rgb.pdf PointOnLine_rgb.png
    
0

If you post your PDF, I can check it out. Otherwise, perhaps it is CMYK, which PNG does not support. So try

magick -quiet -density 300 -colorspace srgb PointOnLine.pdf -quality 90 PointOnLine.png


Note in IM 7, use magick not magick convert. Also not that -quality is different for PNG than JPG. See https://www.imagemagick.org/script/command-line-options.php#quality

fmw42
  • 46,825
  • 10
  • 62
  • 80
-1

I had the same issue and resolved adding -colorspace RGB before the output filename.

convert -density 300 PointOnLine.pdf -quality 90 -colorspace RGB PointOnLine.png
Paz
  • 801
  • 1
  • 10
  • 14