Hey #inkscape folks, a #mastoquestion...

I have an SVG that I want to export into a PNG for use as an icon, which means the image must be square. But the aspect ratio of the original SVG is not.

How can I export the SVG to a square image without stretching it, or else how can I get inkscape (or some other tool) to draw the void space around it?

I'd like to avoid using PIL just for this but will if necessary.

Follow

@emacsen I ended up needed to do the samething with my kids project. What I did is crop the image. Also image-magic is amazing that manipulating images. `convert -background none -size 1024x1024 infile.svg outfile.png`

Using inkscape via cli - `inkscape -z -e out.png -w 1000 -h 1000 in.svg`

stackoverflow.com/questions/98

@nixfreak

Sadly those aren't working for me :(

convert, even specifying 512x512, gives me:

outfile.png: PNG image data, 343 x 464, 8-bit/color RGBA, non-interlaced

Sadly the inkscape cli didnt work at all, other than removing the -z and -e, which is what I got from the beginning.

@nixfreak

I got it!

It took a little wrangling but!

(formatted nicely for readability)

convert -background none \
-resize 180x180 \
-gravity center \
-extent 180x180 \
infile.svg outfile.png

@doctormo I was looking at Inkscape's implementation, and the cairo work is pretty small.

Do you know if something other than Inkscape implements mesh gradients? I'm inclined to supporting them in librsvg, for the sake of compat with Inkscape, but it would be good to know.

Sign in to participate in the conversation
hackers.town

A bunch of technomancers in the fediverse. This arcology is for all who wash up upon it's digital shore.