Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Convert png to svg on the command line
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
marrowhk
Apprentice
Apprentice


Joined: 25 Jul 2007
Posts: 250

PostPosted: Mon Dec 10, 2007 1:45 pm    Post subject: Convert png to svg on the command line Reply with quote

Get inkscape (the cvs nightly builds are better than those in portage in my opinion: http://inkscape.modevia.com/svn-snap/inkscape-current.tar.bz2)
This stumped me for ages!

Remove the portage version of inkscape
emerge -C inkscape

Build the package

./configure
make
make install


Terminal conversion (yeah, it's this simple !) Excellent quality vectors from rasters:

Code:
# inkscape -z -f ~/full/path/to/*.png -l ~/full/path/to/*.svg


This works for png and jpg (obviously adjust png for jpg!)
This won't work unless you use full paths.

Use the following line to convert a directory of png files to svg

Code:
for a in $(find `pwd` -type f -name '*.png'); do inkscape -z -f "$a" -l "${a%.png}.svg"; done

Thanks to jlh for the above one line script
_________________
You'll always come back to GENTOOOOOOO ! (Trust me...)


Last edited by marrowhk on Mon Dec 10, 2007 4:24 pm; edited 3 times in total
Back to top
View user's profile Send private message
jlh
Tux's lil' helper
Tux's lil' helper


Joined: 06 May 2007
Posts: 145
Location: Switzerland::Zürich

PostPosted: Mon Dec 10, 2007 2:26 pm    Post subject: Reply with quote

Maybe you could explain what is better about the cvs nightly builds? New features? Stabler?

I tried your last example that converts PNG files to SVG with portage's inkscape, but it really didn't convert anything; It just creates a SVG file that links back to the original PNG file (open the SVG in a text editor to see that). Or is that precisely what is different in the cvs nightly build?

Here's your one-liner:
for a in $(find `pwd` -type f -name '*.png'); do inkscape -z -f "$a" -l "${a%.png}.svg"; done
It's not semantically the same as yours, as yours will try to convert everything, even files that aren't PNG.
Back to top
View user's profile Send private message
marrowhk
Apprentice
Apprentice


Joined: 25 Jul 2007
Posts: 250

PostPosted: Mon Dec 10, 2007 3:29 pm    Post subject: Reply with quote

jlh wrote:
Maybe you could explain what is better about the cvs nightly builds? New features? Stabler?

I tried your last example that converts PNG files to SVG with portage's inkscape, but it really didn't convert anything; It just creates a SVG file that links back to the original PNG file (open the SVG in a text editor to see that). Or is that precisely what is different in the cvs nightly build?

Here's your one-liner:
for a in $(find `pwd` -type f -name '*.png'); do inkscape -z -f "$a" -l "${a%.png}.svg"; done
It's not semantically the same as yours, as yours will try to convert everything, even files that aren't PNG.


Many thanks for the one liner! :)

The cvs is closer to the new 0.46 which as far as i can tell is the only version of inkscape which can cope effectively with the cli conversion. If you try the nightly build you'll see the conversion is complete. by the way the conversion is to plain svg (*.svg) not *.SVG (inkscape and sodipodi svg).

NOTE:

Just checked the resulting *.svg files again by copying them over to my wife's PC without the original pngs - All good! It must be the 0.46 build over portage's 0.45.x build.

Here's another question for you that's been bugging me, if you have the time:

I'm trying to convert an icon theme from png to svg (scalable). I can do all i need to do but I'm stumped by how to cleanly relink the new svg's to the old links which previously linked to the old png's! Its a lot of work to go through everything one file at a time. Would you know and effective method of doing this for multiple links?

Originally:
icon53link.png --> icon1.png (--> = link)
===========================
icon1.png converted to icon1.svg
icon53link.png converted to icon53link.svg

Now:
:: icon53link.svg --> icon1.png (--> = link)
++++++++++++++++++++++++++
can i relink icon53link.svg on the command line to point to icon1.svg rather than icon1.png ?
_________________
You'll always come back to GENTOOOOOOO ! (Trust me...)
Back to top
View user's profile Send private message
jlh
Tux's lil' helper
Tux's lil' helper


Joined: 06 May 2007
Posts: 145
Location: Switzerland::Zürich

PostPosted: Tue Dec 11, 2007 12:01 am    Post subject: Reply with quote

Ok, I might have a look at cvs nightly builds.

Here's what you can do to fix your symlinks:
for X in $(find -L . -type l); do L=$(readlink "$X"); N="${L%.png}.svg"; test -e "$N" && ln -vfs "$N" "$X" || echo "Can't find new target for $X -> $L"; done

Note how find -L . -type l *only* finds broken symlinks. It won't rename the symlinks themselves, as you said you renamed them already. And it will only fix the link if the actual target exists.
Back to top
View user's profile Send private message
marrowhk
Apprentice
Apprentice


Joined: 25 Jul 2007
Posts: 250

PostPosted: Tue Dec 11, 2007 12:47 pm    Post subject: Reply with quote

jlh wrote:
Ok, I might have a look at cvs nightly builds.

Here's what you can do to fix your symlinks:
for X in $(find -L . -type l); do L=$(readlink "$X"); N="${L%.png}.svg"; test -e "$N" && ln -vfs "$N" "$X" || echo "Can't find new target for $X -> $L"; done

Note how find -L . -type l *only* finds broken symlinks. It won't rename the symlinks themselves, as you said you renamed them already. And it will only fix the link if the actual target exists.


Your help is really appreciated. I shall go through this thoroughly so i learn from it!

Thanks again jih.

_________________
You'll always come back to GENTOOOOOOO ! (Trust me...)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum