Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

INPUT:

enter image description here

OUTPUT:

enter image description here

share|improve this question

3 Answers 3

up vote 2 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

Documentation: http://www.imagemagick.org/Usage/crop/#extent

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
1  
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

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:

 449x352

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:

 520x352

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) \
    out2.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:)
 done

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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