You are not logged in.

#1 2006-08-07 22:41:46

whargoul
Member
From: Odense, Denmark
Registered: 2005-04-04
Posts: 546

Converting SVG's to PNG's

Hi

So I'm trying to convert all these SVG's to PNG's via ImageMagick. If I'm not wrong, the command is 'convert -define /path/to/icon.svg /path/to/icon.png'. Well that takes a long time with all those icons in yasis, so I thought that a script would help, but I don't know how it should look?

But at least something like this:

#!/bin/sh

for i in *;
do
        convert -define ./scalable/apps/$i ./48x48/apps/$i;
done

That's just bring us the problem that the SVG's aren't converted to PNG's, so how do I do it?


Arch - It's something refreshing

Offline

#2 2006-08-07 22:47:19

dtw
Forum Fellow
From: UK
Registered: 2004-08-03
Posts: 4,439
Website

Re: Converting SVG's to PNG's

I'd try:

list=`find * -type f -name "*.svg"`
for i in $list ; do
convert -define ./scalable/apps/$i ./48x48/apps/$i
done

Not convinced ./48x48/apps/$i will give you what you want though, surely the output file will be called *.svg anyway?  Even if it is a .png file...

Offline

#3 2006-08-07 22:58:59

whargoul
Member
From: Odense, Denmark
Registered: 2005-04-04
Posts: 546

Re: Converting SVG's to PNG's

dtw wrote:

I'd try:

list=`find * -type f -name "*.svg"`
for i in $list ; do
convert -define ./scalable/apps/$i ./48x48/apps/$i
done

Not convinced ./48x48/apps/$i will give you what you want though, surely the output file will be called *.svg anyway?  Even if it is a .png file...

I thought something like to cut of ".svg" extension and replace it with ".png". But I'll try it to se if it works.


Arch - It's something refreshing

Offline

#4 2006-08-07 23:04:27

whargoul
Member
From: Odense, Denmark
Registered: 2005-04-04
Posts: 546

Re: Converting SVG's to PNG's

No it doesn't work. I got this output:

convert: missing an image filename `./48x48/apps/22x22/filesystems/gnome-fs-network.svg'.
convert: missing an image filename `./48x48/apps/24x24/apps/gnome-window-manager.svg'.
convert: missing an image filename `./48x48/apps/24x24/devices/SVGs/gnome-dev-floppy.svg'.
convert: missing an image filename `./48x48/apps/24x24/devices/SVGs/gnome-dev-cdrw.svg'.
convert: missing an image filename `./48x48/apps/24x24/devices/SVGs/gnome-dev-disc-dvdr.svg'.
...

And it continues.


Arch - It's something refreshing

Offline

#5 2006-08-08 01:13:24

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Converting SVG's to PNG's

If all of your svg images are in one directory, you can run this script. The only drawback is that your files will go from "image.svg" to "image.svg.png". It works though. If you feel like the naming is no good, you could do a batch renaming with 'rename'.

for img in `ls *.svg`
do
  convert $img $img.png
done

Offline

#6 2006-08-08 02:39:32

linfocito
Member
From: Gurupi - TO, Brasil
Registered: 2003-05-18
Posts: 82

Re: Converting SVG's to PNG's

Renaming *.svg.png to *.png:

1. execute the code of the above post inside ./scalable/apps/, then do:

cd ../..
mv  ./scalable/apps/*.svg.png  ./48x48/apps/
cd ./48x48/apps
ls *.svg.png > chgname.sh
sed -i "s|^.*$|& &|" chgname.sh
sed -i "s|^|mv |" chgname.sh
sed -i "s|svg.png$|png|" chgname.sh
sh chgname.sh
rm chgname.sh

"...archoholism is a hard disease to cure..."
Archlinux Brasil

Offline

#7 2006-08-08 02:57:50

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: Converting SVG's to PNG's

The following will rename the files and give them the correct extensions. I've also removed the -define option. It doesn't seem to be necessary and was incomplete.

#!/bin/bash
list=`find * -type f -name "*.svg"`
for i in $list ; do
convert  ./scalable/apps/$i ./48x48/apps/$(basename $i .svg).png
done

Offline

#8 2006-08-08 03:07:28

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Converting SVG's to PNG's

I'm going for the pretty code award:

for img in `ls *.svg`
do
  convert $img $img.png
done

rename .svg.png .png *.svg.png

Offline

#9 2006-08-08 11:34:46

JGC
Developer
Registered: 2003-12-03
Posts: 1,664

Re: Converting SVG's to PNG's

for img in *.svg; do
  convert ${img} `basename ${img}`.png
done

Offline

#10 2006-08-08 11:53:58

dtw
Forum Fellow
From: UK
Registered: 2004-08-03
Posts: 4,439
Website

Re: Converting SVG's to PNG's

Snowman wrote:

The following will rename the files and give them the correct extensions. I've also removed the -define option. It doesn't seem to be necessary and was incomplete.

#!/bin/bash
list=`find * -type f -name "*.svg"`
for i in $list ; do
convert  ./scalable/apps/$i ./48x48/apps/$(basename $i .svg).png
done

Snowman ftw, surely?  Everyone else has ignored the output dir!

Offline

#11 2006-08-08 12:14:33

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Converting SVG's to PNG's

dtw wrote:

Snowman ftw, surely?  Everyone else has ignored the output dir!

Nope. We simply didn't hard code a solution to one single instance; instead the code is generic enough to be easily transportable. Although, adding the functionality to query for file type to and from, plus input and output directories may be kind of cool... if one has a repeated need.

I believe that JGC's solution is the cleanest of all. Nice.

Offline

#12 2006-08-08 13:30:59

whargoul
Member
From: Odense, Denmark
Registered: 2005-04-04
Posts: 546

Re: Converting SVG's to PNG's

Thanks for all your help. smile


Arch - It's something refreshing

Offline

#13 2006-08-08 15:26:45

dtw
Forum Fellow
From: UK
Registered: 2004-08-03
Posts: 4,439
Website

Re: Converting SVG's to PNG's

skottish wrote:

We simply didn't hard code a solution to one single instance; instead the code is generic enough to be easily transportable.

Hardcoded and transportable my ass!  In its current state it doesn't do what was requested: specifically output to a different dir lol

_If_ the vars you went on to suggest had been included then I'd heartily agree...but they weren't.  So there  tongue

Offline

Board footer

Powered by FluxBB