Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize canvas of svg images in command line

I have bunch of svg images (1.svg 2.svg ...) and i would like to center them and resize canvas to the same value for all of them. Let's say that image 1.svg has w. 600 and h. 800 and 2.svg has w. 1000 and h. 400. I would like to set canvas for both as 1000x800 and center images. As the result the images won't be resized, but they will have extra space on sides -> 1.svg will still be 600x800 but in canvas with size 1000x800 and 2.svg will be 1000x400 but in canvas with size 1000x800. Is it possible to do in command line? Using inkscape, imagemagick etc.?

Thanks in advance!

like image 562
Dsi Avatar asked Jan 27 '17 07:01

Dsi


1 Answers

You need the -extent option to ImageMagick, like this:

convert 1.svg -gravity center -background yellow -extent 1000x800 result.png

So, let's make some images:

convert -size 600x800! xc:red 1.png
convert 1.png -gravity center -background yellow -extent 1000x800 result.png

enter image description here

Or the other way:

convert -size 1000x400! xc:red 2.png
convert 2.png -gravity center -background blue -extent 1000x800 result.png

enter image description here

like image 176
Mark Setchell Avatar answered Oct 02 '22 15:10

Mark Setchell