[Resolved] Page misalignment converting PNG to PDF

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
HelenF
Posts: 3
Joined: 2016-06-11T07:57:01-07:00
Authentication code: 1151

[Resolved] Page misalignment converting PNG to PDF

Post by HelenF »

Hi,

I had pages in PNG format, edited in Kolourpaint, and was trying to use ImageMagick to assemble them into a PDF file with one image per page. In the generated PDF file, some of the pages were correct, but some of the pages had uneven margins (not all in the same direction).

I was using ImageMagick 6.8.8-10 Q16 i686 2015-03-10 on Fedora 22 (viewing in Evince). Downloaded and installed the updated ImageMagick-7.0.1-10-Q8-x64-dll.exe on Windows 10 (and viewed with Adobe Reader) and it behaved the same.

This could be a Kolourpaint bug, or a feature, but here seems like the place to check.

Here is a test image that shows the behaviour when converted to a 1-page PDF by itself:
https://www.dropbox.com/s/tksin9t7wn8c2 ... n.zip?dl=1

Drawing of the results:
Image

Code: Select all

convert test.png test.pdf
The image is shifted to the south-west on the page, and because there are no added margins, two of the edges are cut off (1).

Code: Select all

convert test.png test.bmp
convert test.bmp test.pdf
This is OK (2). So if there was a problem with the PNG file, it's not there in the BMP.

Code: Select all

convert test.bmp test2.png
convert test2.png test.pdf
This is OK (2). So if there was a problem with the PNG file, it was fixed by converting to BMP and back.

Code: Select all

convert -flip test.png test2.png
convert test2.png test.pdf
The image is shifted to the north-west on the page (3). So if there was a problem with the PNG file, it was preserved (and flipped) by the flip operation.
Last edited by HelenF on 2016-06-14T09:46:20-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Page misalignment converting PNG to PDF

Post by snibgo »

"identify test.png" shows the file has offsets in x and y. "+repage" removes these.

Code: Select all

convert test.png +repage out.pdf
snibgo's IM pages: im.snibgo.com
HelenF
Posts: 3
Joined: 2016-06-11T07:57:01-07:00
Authentication code: 1151

Re: Page misalignment converting PNG to PDF

Post by HelenF »

Thanks for the help. I can make my document now :)

I remembered that I rotated some of the pages with ImageMagick before editing them. Looks like that operation added the offsets without me noticing. Kolourpaint just preserves the offsets when editing the file. And converting to PDF finally makes them visible. This is equivalent (though the result is less obvious when I haven't cropped the edges):

Code: Select all

convert -rotate -0.5 anyimage.png anytest.png
convert anytest.png anytest.pdf
I noticed something else with the test image and example commands in the first post. With the first two examples on my Windows setup, the magenta colour is dulled significantly. Why is this? With the last two examples on my Windows setup, and all four on my Fedora setup, it stays the same.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Page misalignment converting PNG to PDF

Post by snibgo »

Your command order is wrong. You should read the input, then do whatever operation on it you want, then wite the output.

Rotating creates an offset. If you don't need the offset, you can immediately remove it, eg:

Code: Select all

convert anyimage.png -rotate -0.5 +repage anytest.png
convert anytest.png anytest.pdf

convert anyimage.png -rotate -0.5 +repage anytest.pdf
HelenF wrote:With the first two examples on my Windows setup, the magenta colour is dulled significantly.
What tells you "the magenta colour is dulled significantly"? I can't see that. "-unique-colors" shows all colours are unchanged.
snibgo's IM pages: im.snibgo.com
HelenF
Posts: 3
Joined: 2016-06-11T07:57:01-07:00
Authentication code: 1151

Re: Page misalignment converting PNG to PDF

Post by HelenF »

The order was because in reality, there were manual operations in between.

Thanks, I will immediately remove the offsets next time.

With the first two examples, the magenta looked wrong in Adobe Reader 10.1.16. But I updated Adobe Reader (much overdue) and the same PDF files look the right colour now.
Post Reply