I want to convert a PDF to a PNG while also trimming any white space and get a PNG that does not display everywhere (e.g. Firefox shows an error) and I also get a warning when I try to determine the image width with the "identify" command. Since this only happens with one of about 20 similar PDFs, I suspect this might be a bug. In addition, the generated PNG is quite large and when I formally "convert <same-width>" the PNG to a copy that copy is much smaller - this may rather be a usage issue, but I am not sure.
Step by step (URLs to the files further below)
Code: Select all
$ convert -density 300 -flatten -trim +repage moebius.pdf PNG32:moebius.png
$ ls -l moebius.pdf moebius.png
-rw-r--r--@ 1 alain staff 4409825 Feb 23 16:01 moebius.pdf
-rw-r--r--@ 1 alain staff 7787908 Feb 24 09:34 moebius.png
That moebius.png opens fine in Photoshop (CS5.1) and in Safari and Chrome Browsers, but in Firefox (current, 65.0.1) I get an error "The image [url] cannot be displayed because it contains errors."
When I open in in Apple's Preview Application, it cuts off exactly 11 pixels on the right border of the image.
(After I click anywhere in the image, then it also shows these 11 pixels until I close the image again.)
Code: Select all
$ identify -format "%w" moebius.png
identify: zTXt: truncated `moebius.png' @ warning/png.c/MagickPNGWarningHandler/1744.
1012
Then I tried this:
Code: Select all
$ convert -resize 1012 moebius.png moebius2.png
convert: zTXt: truncated `moebius.png' @ warning/png.c/MagickPNGWarningHandler/1744.
$ ls -l moebius2.png
-rw-r--r--@ 1 alain staff 2779622 Feb 24 09:34 moebius2.png
$ identify -format "%w" moebius.png
identify: zTXt: truncated `moebius.png' @ warning/png.c/MagickPNGWarningHandler/1744.
1012
This is close to the size I get when copying+pasting+exporting moebius.png in Photoshop (2.4 MB), which is roughly what I would have hoped for and I think also got roughly with some older version of ImageMagick a couple of years back.
Interestingly that image moebius2.png displays without error on Firefox (and also fine in Safari and Chrome).
Behavior in Apple Preview and the warning that "identify" shows remain the same, however.
I have used the current version of ImageMagick (7.0.8-9) downloaded as tgz from this site, after I had the same behavior (different line number in warning) with a 6.x.x. version installed with macports (now all macport versions uninstalled). I am on OS X 10.12.6 "Sierra".
Code: Select all
$ convert -version | grep Version
Version: ImageMagick 7.0.8-9 Q16 x86_64 2018-08-04 https://www.imagemagick.org
in: https://www.artecat.ch/jexler/moebius/moebius.pdf
out 1: https://www.artecat.ch/jexler/moebius/moebius.png
out 2: https://www.artecat.ch/jexler/moebius/moebius2.png
Questions
- Am I maybe doing something wrong or unusual? (As I said, about 20 very similar PDFs convert without warnings and open without problems in Firefox and other browser - although all of them are larger than expected)
- Besides the possible bug, is there a way to get a smaller result with a single call to convert?