Adding whitespace around an image to make it the right size

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
roger_pearse

Adding whitespace around an image to make it the right size

Post by roger_pearse »

I hardly ever use ImageMagick, excellent tho it is, so I hope that people will bear with me if I'm asking a silly question.

I want to reprint an old book on lulu.com. I've scanned the pages as images (jpgs). But each image is smaller than the page size that lulu want.

What this means is that lulu resize the image to fill the space, which distorts it.

What I want to do is to put whitespace all the way around the image, to fill it out to the size (in inches or cms) that I need. In this way the image of the page text will remain the same size, but the actual file will be larger.

Can anyone tell me how best to do this? I saw the -border, but this seemed to involve me specifying the width of the border, rather than the end-size of the image.

Suggestions very welcome.

All the best,

Roger Pearse
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adding whitespace around an image to make it the right size

Post by fmw42 »

use -extent with -gravity

see http://www.imagemagick.org/Usage/crop/#extent
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Adding whitespace around an image to make it the right size

Post by Bonzo »

Why don't you just create a blank white image the correct size and put your other image onto it?

Code: Select all

convert -size 400x600 xc:white page.jpgs -gravity center -composite output.jpgs
You will need to work out the size but when you have it correct it will work for all the pages.
roger_pearse

Re: Adding whitespace around an image to make it the right size

Post by roger_pearse »

Ah! Yes, of course that would work, wouldn't it?! Thank you for the syntax -- I'll try that.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Adding whitespace around an image to make it the right size

Post by anthony »

There are about a dozen methods you can use for 'padding' an image. The above are the two best methods... See
http://imagemagick.org/Usage/thumbnails/#pad
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
roger_pearse

Re: Adding whitespace around an image to make it the right size

Post by roger_pearse »

Thank you also -- ah, I knew it had to be an FAQ!

Roger
Post Reply