Centering too big images doesn't work with 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
Sworddragon
Posts: 7
Joined: 2012-04-11T11:57:55-07:00
Authentication code: 8675308

Centering too big images doesn't work with pdf

Post by Sworddragon »

I'm using ImageMagick 6.7.7.10 and there is a centering issue on convert with the option -gravity. First I have created 2 black images with the size of 100x100 and 1000x1000.

Trying to convert the small image works like expected: "convert test100.png -gravity center -page A4 test100.pdf"
The image is horizontally and vertically aligned in the middle of the document.

But trying this with the big image makes troubles: "convert test1000.png -gravity center -page A4 test1000.pdf"
The image isn't aligned in the middle anymore. It just draws from ~the middle to the down left corner. The most parts of the image are hidden in this case.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Centering too big images doesn't work with pdf

Post by snibgo »

On Windows 7, the following works as it should for 6.7.9-6 and 6.8.1-10. It fails for 6.8.2-0, creating PDF files that are unreadable by Adobe Reader or IM "identify".

Code: Select all

convert -size 100x100 xc:black test100.png
convert -size 1000x1000 xc:black test1000.png

convert test100.png -gravity center test100.pdf
convert test1000.png -gravity center test1000.pdf

identify test100.pdf
identify test1000.pdf
snibgo's IM pages: im.snibgo.com
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Centering too big images doesn't work with pdf

Post by magick »

This bug is fixed in ImageMagick 6.8.2-7, the current release.
Sworddragon
Posts: 7
Joined: 2012-04-11T11:57:55-07:00
Authentication code: 8675308

Re: Centering too big images doesn't work with pdf

Post by Sworddragon »

I'm still seeing this bug in ImageMagick 6.8.9.9-2.
timoths
Posts: 1
Joined: 2014-11-18T14:05:42-07:00
Authentication code: 6789

Re: Centering too big images doesn't work with pdf

Post by timoths »

The bug is still present in ImageMagick 6.8.9-9 Q16 i586 2014-10-28. To reproduce it:

Code: Select all

convert -size 100x100 xc:black test100.png
convert -size 1000x1000 xc:black test1000.png

convert test100.png -gravity center -page A4 test100.pdf
convert test1000.png -gravity center -page A4 test1000.pdf
Expected result: Both images are centered.
Actual result: The small image is centered but the big image is not, just as described in the OP.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Centering too big images doesn't work with pdf

Post by fmw42 »

confirmed non-centered large image result IM 6.9.0.0 Q16 Mac OSX
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Centering too big images doesn't work with pdf

Post by glennrp »

The 1000x1000 is just too large to compose on a 595x842 A4 page.
I'm not sure what the "correct" behavior would be. Center it, then crop to fit the page?
Note that -size 500x800 works as well, but 600x850 is incorrectly offset.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Centering too big images doesn't work with pdf

Post by fmw42 »

My understanding is that -page media is supposed to resize, position and respect -gravity for postscript files. See


"For a PostScript page, the image is sized as in -geometry but positioned relative to the lower left-hand corner of the page by {+-}xoffset{+-}y offset. Use -page 612x792, for example, to center the image within the page. If the image size exceeds the PostScript page, it is reduced to fit the page. The default gravity for the -page option is NorthWest, i.e., positive x and y offset are measured rightward and downward from the top left corner of the page, unless the -gravity option is present with a value other than NorthWest."

see
http://www.imagemagick.org/script/comma ... s.php#page

But the centering fails for:

Code: Select all

convert -size 1000x1000 xc:black test1000.png

convert test1000.png -gravity center -page A4 test1000.ps
or
convert test1000.png -gravity center -page A4+0+0 test1000.ps

I must admit that the paragraph above from the options page is very confusing:

1) It first says the default geometry is relative to the lower left corner, which would be SouthWest
2) Then it says to center just use -page 612x792, which has no offsets specified
3) Then it says the default gravity is Northwest

This paragraph badly needs a rewrite to make it clear how to use it.


It also is not clear if -page is to process an input .ps file or to create a new .ps file. I was assuming the latter, but it may only be relevant to the former.

In any case, I have no real experience with -page (other than for use with -flatten). I would recommend using -resize and -extent, specifying pixel dimensions for processing images in order to resize and pad to the desired page size in pixels.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Centering too big images doesn't work with pdf

Post by glennrp »

The paragraph is indeed confusing. It has survived intact since the oldest ImageMagick version that I have (4.2.7, June 1999), which was before "-resize" and "-extent" existed. I think the confusion arose mostly from the fact that the default coordinate system for PostScript has the origin at the lower left (Southwest) corner. I can't build that old version to see if it worked as described back then.
Post Reply