Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What parameters does "convert" (?) need to get this OUTPUT from this INPUT?


enter image description here


enter image description here

share|improve this question
up vote 3 down vote accepted

As I didn't want the images flush with the right side, I had to use a different approach (ImageMagick's composite tool):

convert -size 500x500 xc:white canvas.png
convert canvas.png in.png -geometry +200+200 -composite out.png

-size should be the final image size you want, canvas.png is a blank white canvas, in.png would be the image you want to pad, and -geometry is the positioning offset.

share|improve this answer


convert in.png -gravity east -extent 500x352 out.png
share|improve this answer
Thanks!! But what if my picture is not 500x352 - because the size varies? – gasko peter Jul 3 '12 at 22:44
I just show you how to. – kev Jul 3 '12 at 22:58
@kev: Your command doesn't exactly do what @gasko peter wanted. You should have used -extend 520x352. +1 for the 'right direction' though :-P – Kurt Pfeifle Jul 9 '12 at 18:45
sed 's#-extend#-extent#g' – Kurt Pfeifle Aug 6 '12 at 20:15
I had to add -background transparent to preserve a transparent background. – tremby Jul 4 at 23:27

My ImageMagick version is '6.7.8-0 2012-07-04 Q16'. According to the docu the answer of @kev command should work:

 convert in.png -gravity east -extent 520x352 out.png

However, like with most ImageMagick questions, you can achieve the same goal with different means. You could use montage like this:

 montage null: in.png -tile 2x1 -geometry +17+0 out1.png

This uses the special 'null:' image to concatenate it with the in.png.

It is true that with convert you need to re-compute the values you need to pass to -extent for each input picture that's got a different size.

First use identify -format to get the dimensions of the image:

 identify -format '%Wx%H' in.png

This should return something like:


Ok, now you would need to add your wanted 71 pixels, to get the final 520x352 value. But you don't need to do that calculation in your own brains:

ImageMagick to the rescue!, and its magic calculation capabilities... :-)

You can tell the identify -format command to do that calculation for you:

 identify -format '%[fx:W+71]x%H'

This should now give you a result of:


So assuming you want to just pad/add a 'white strip' of 71 pixels width to the left of any picture, you can use the following single commandline:

 convert \
    in.png \
   -gravity east \
   -background white \
   -extent $(identify -format '%[fx:W+71]x%H' in.png) \

Voila! One commandline (which encapsulates 2 commands, to be honest) and you can let this one loose on all your PNGs, JPEGs, GIFs,... in a directory to auto-magickally add your 71pixels white strip to each of them:

 for i in *.png *.jpeg *jpg *.gif; do
    convert \
       ${i} \
      -gravity east \
      -background white \
      -extent $(identify -format '%[fx:W+71]x%H' ${i}) \
       $(convert ${i} -format "71-pixels-padded-left---%t.%e" info:)

For each image its output remains the same filetype. Of course you can enforce all output to be PNG (or whatever you want). Just replace the %t.%e part of the command with %t.png...

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .