Hi, I'm trying to batch resize and convert 1000+ svgs to pngs and I'm very confused.
Ideally I'd like to resize all the svgs to 2160pixels x 2160pixels and then convert them to png.
So far I can only convert and resize one at a time by typing the file name in manually and the end result is a mess as it's just a resized 64x64 image which looks terrible.
I imagine this is very simple but what commands would you use to do this with a few clicks? honestly I've been wrestling with his for over a day, sorry, my brain doesn't work like it used to!
Resize 1000 svgs to 2160x2160
then convert to png
Converting and resizing svgs to pngs
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
cRe: Converting and resizing svgs to pngs
In essence, this is easy. Do it one file at a time with convert, and put that inside a shell for loop:
Or use a single mogrify:
However, SVGs are vector files, probably containing only vector data. If the "natural" rasterization is smaller than 2160 pixels, they will be enlarged, which may look bad. You might prefer to include "-density N" before the SVG file, where N is an integer such as 150 or 600, and depends on a few things.
Code: Select all
convert in.svg -resize 2160 out.png
Code: Select all
mogrify -resize 2160 -type png *.svg
snibgo's IM pages: im.snibgo.com
Re: Converting and resizing svgs to pngs
Thanks I ended up getting there after even more head scratching. Ran into a few problems like the transparencies turned to pure white so a bit of googling and I discovered the "-background none" option and yeah I needed to add the -density and I couldn't get your mogrify code working but I got there eventually so thanks!
the actual final command I used was
Fascinating little bit of real software in this day and age of apps.
the actual final command I used was
I guess the density amount was a bit OTT and the svgs came out at 3555px but that was ok and I'm very happy. I almost paid someone money to do it for me!"mogrify -background none -density 5000 -format png *.svg"
Fascinating little bit of real software in this day and age of apps.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Converting and resizing svgs to pngs
Good stuff.
The default density is 90 dpi. So if your first-try rasterization comes out at 64 pixels wide and you want it 2160 pixels wide, use a density of 90 * 2160/64 = 3037.5 or thereabouts. Or use 10% larger, and resise down to the exact size you want.
The default density is 90 dpi. So if your first-try rasterization comes out at 64 pixels wide and you want it 2160 pixels wide, use a density of 90 * 2160/64 = 3037.5 or thereabouts. Or use 10% larger, and resise down to the exact size you want.
snibgo's IM pages: im.snibgo.com