Is it possible to write a script that can create a copy of all the pictures in a file and add a white border to it with the border multiplied by a certain percentage?

I want the width of the new image (old image + border) to be about 134% of the old one and height about 165% of the old one.

I imagine this is fairly simple but not positive how and all my attempts so far have been unsuccessful.

My current code so far is:

'''for i in ls; do name = "mat_$i" echo "processing $name..." ; convert $i -bordercolor white -border 1x2 $name; done''''

The 1x2 is off for sure, but nothing I have tried there worked either.

I would also like to add meta data as some of these pics are professional and maybe distributed online. Thanks in advance.

1

There are 1 answers

0
fmw42 On

Here is one way for Imagemagick 6.

Input:

enter image description here

infile="barn.jpg"
bgcolor="red"
inname=`convert "$infile" -format "%t" info:`
declare `convert "$infile" -format "ww=%[fx:w*134/100]\nhh=%[fx:h*165/100]" info:`
convert -size ${ww}x${hh} xc:"$bgcolor" "$infile" -gravity center -composite "${inname}_pad.jpg"

Result:

enter image description here

For Imagemagick 7, you can do that inline as follows:

magick barn.jpg -size "%[fx:w*134/100]x%[fx:h*165/100]" xc:red +swap -gravity center -composite barn_pad.jpg