Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6612781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:08:21+00:00 2026-05-25T20:08:21+00:00

I’m using convert version ImageMagick 6.6.2-6 2011-03-16, and I’d like to use it to

  • 0

I’m using convert version ImageMagick 6.6.2-6 2011-03-16, and I’d like to use it to generate an A4 pdf from an image, where the image will be non-scaled and centered.

I’m running the following (as a modification of Overlaying Images with ImageMagick):

# generate a 100x100 JPG with just red color
convert -size 100x100 xc:red red.jpg

# generate PDF from JPG
convert -page A4 xc:white red.jpg -gravity center -composite -format pdf out.pdf

… but, basically nothing shows? Same thing happens for a png image…

Note that

  • Just ‘convert -page A4 red.jpg out.pdf‘ works – but the image is not centered; (-gravity center causes image not to show)
  • If the image is png, ‘convert -page A4 -gravity center red.png out.pdf‘ does indeed work fine

… however, I’d like convert to embed the contents of the JPEG stream directly – hence, I wouldn’t like to convert the JPG to PNG first.

So, would it be possible to use convert to center a JPG image in an A4 PDF page directly?

Many thanks in advance for any answers,
Cheers!

 

EDIT2: @John Keyes answer works for the example above; where the image is “smaller” than the PDF size — however if the image is bigger, e.g.:

$ convert -size 1228x1706 -background \#f44 -rotate 45 gradient:\#f00-\#fff red.jpg
$ identify red.jpg 
red.jpg JPEG 2075x2075 2075x2075+0+0 8-bit DirectClass 120KB 0.000u 0:00.000

… then it will fail. However, it turns out: “if you change -extent to 50×50, then play with -gravity, you’ll see changes” – except, the question is: which extent do you change, that of the image – or that of the final PDF?

Well, it turns out – it is the extent of the final PDF… To find that size as convert sees it, check the page: Magick::Geometry – however, note that the “Postscript page size specifications” like “A4+43+43>” unfortunately, cause convert to crash in this context… But at least the respective numbers for the size (595×842) can be copied from the page; and finally this works:

convert -page A4 -gravity center -resize 595x842 -extent 595x842 red.jpg out.pdf

… and actually, the -extent part is not really needed – the -resize part is the important one to have the large image show..

However, the problem here is that the image included seems to be resampled – however, I’d just like to show it scaled so it fits the page, but would otherwise like the original JPG stream to be inserted in the file.. So I guess the question is still partially open 🙂

EDIT: Related:

  • ImageMagick Gravity parameter – Stack Overflow
  • ImageMagick and Geometry Issue – resizing with > – Stack Overflow
  • command line – Resizing and croping images to an aspect ratio of 6×4 with width of 1024 pixels – Unix and Linux – Stack Exchange
  • conversion – using imagemagick or ghostscript (or something) to scale PDF to fit page? – Stack Overflow
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:08:22+00:00Added an answer on May 25, 2026 at 8:08 pm

    The following works perfectly for me:

    convert -page A4 red.jpg  -gravity center -format pdf out.pdf
    

    and if you change the order of the “files” it works too:

    convert -page A4 red.jpg xc:white -gravity center -composite -format pdf out.pdf
    

    I think the red.jpg is centered but the white is drawn on top of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.