Page 1 of 1
Centering too big images doesn't work with pdf
Posted: 2013-02-08T02:59:57-07:00
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.
Re: Centering too big images doesn't work with pdf
Posted: 2013-02-08T05:40:32-07:00
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
Re: Centering too big images doesn't work with pdf
Posted: 2013-02-08T06:00:52-07:00
by magick
This bug is fixed in ImageMagick 6.8.2-7, the current release.
Re: Centering too big images doesn't work with pdf
Posted: 2014-10-30T21:03:24-07:00
by Sworddragon
I'm still seeing this bug in ImageMagick 6.8.9.9-2.
Re: Centering too big images doesn't work with pdf
Posted: 2014-11-18T14:16:00-07:00
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.
Re: Centering too big images doesn't work with pdf
Posted: 2014-11-18T14:59:16-07:00
by fmw42
confirmed non-centered large image result IM 6.9.0.0 Q16 Mac OSX
Re: Centering too big images doesn't work with pdf
Posted: 2014-11-18T16:35:24-07:00
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.
Re: Centering too big images doesn't work with pdf
Posted: 2014-11-18T17:04:58-07:00
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.
Re: Centering too big images doesn't work with pdf
Posted: 2014-11-19T12:47:22-07:00
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.