user585440
user585440

Reputation:

Error in converting images in Imagemagick

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.

Upvotes: 9

Views: 9825

Answers (5)

Paz
Paz

Reputation: 921

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

Upvotes: -1

D555
D555

Reputation: 1832

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

Upvotes: 2

fmw42
fmw42

Reputation: 53089

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!

Upvotes: 4

fmw42
fmw42

Reputation: 53089

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

Upvotes: 0

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
    

Upvotes: 1

Related Questions