简体   繁体   中英

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.

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

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!

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

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

我遇到了同样的问题并解决了在输出文件名之前添加 -colorspace RGB 的问题。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM