1

I'm want to add to my pictures in Imagemagick:

  • white colored border
  • 2 inches wide

How can I do it?

2
convert -border 20 -bordercolor white input.jpg output.jpg

will add a white border of size 20 pixels to image. You just need to find out how much px is an inch (dpi) of image.

More examples can be found here.

In case of my test image, it had saved dpi info in it. I could get it using identivy -verbose and it look like this:

$ identify -verbose tiger.jpg
Image: tiger.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 600x400+0+0
  Resolution: 96x96
  Print size: 6.25x4.16667
  Units: PixelsPerInch
  Type: TrueColor
...

As you can see, it has 96x96 dpi as units are of type PixelsPerInch.

In that case 2 inches on my image is 192px.

  • I want to add 2 inches, how can ? – Deniz Sep 1 '16 at 9:29
  • if your image have somehow saved dpi info in it, you should be able to get it using identify -verbose. Images normally do not have that info – V-master Sep 1 '16 at 9:36
0

First, find out how many pixels the 2" border will have. Add these pixels to the #pixels of your original Image (twice, as you want the same border on each side).

Now use convert like

convert <input> -size <newsize> xc:white +swap -gravity center -composite <output>

Let's say, the image size is 3600x2400, and the resolution is 100px/in. So you have to add 400px to each dimension, getting 4000x2800 as the result. (How to find out these values has been described by @V-master). Then the command reads (where input.jpg is the original and output.jpg is the result)

convert input.jpg -size 4000x2800 xc:white +swap -gravity center -composite output.jpg

For me this worked as requested.

Edit:

convert input.jpg -bordercolor white -border <n> output.jpg

(as already suggested by @V.master) works as well, only -bordercolor option has to be defined before -border. It is a shortcut for my suggestion, which I use to have borders of different size (rsp. fixed aspect ratio independent of that of the original image).

There is no option to set the unit to inches. What 2" are depends on the output resolution of your picture when being printed (eg. 300dpi: n=600, 600dpi: n=1200 etc.).

  • Does it keep the image dimensions or the border goes outside? – Sigur Feb 22 '19 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.