Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert png to svg using imagemagick and potrace
#!/bin/bash
if [ "$1" == "" ]; then
echo Usage: $0 pngfile
exit 0;
fi
FILE=`basename $1 .png`
if [ ! -e $FILE.png ]; then
echo $FILE.png does not exist
exit 1;
fi
convert $FILE.png $FILE.pnm
potrace -s -o $FILE.svg $FILE.pnm
rm $FILE.pnm
@winc-oops
Copy link

winc-oops commented Apr 14, 2020

hello, noob question... Im running zsh in mac instead of bash... png2svg.sh with the !#/bin/bash shebang works; why?
and why does it not work if I change the shebang to zsh one and the ext to zsh? thnx

@ykarikos
Copy link
Author

ykarikos commented Apr 15, 2020

hello, noob question... Im running zsh in mac instead of bash... png2svg.sh with the !#/bin/bash shebang works; why?
and why does it not work if I change the shebang to zsh one and the ext to zsh? thnx

Hi @Wiruu! The !#/bin/bash means that the script will always be run in bash. The script syntax is bash, not zsh and that's why it would not work with !#/bin/zsh. The filename extension does not affect how it is run. I hope this helps!

@winc-oops
Copy link

winc-oops commented Apr 15, 2020

does a lot thnx...

@myselfhimself
Copy link

myselfhimself commented Nov 4, 2020

You may struggle if you do not apply high or low pass filters first. See http://potrace.sourceforge.net/mkbitmap.html

@AntumDeluge
Copy link

AntumDeluge commented Dec 31, 2020

Alternate command: convert infile.png pnm:- | potrace -s -o outfile.svg

@ykarikos
Copy link
Author

ykarikos commented Dec 31, 2020

Alternate command: convert infile.png pnm:- | potrace -s -o outfile.svg

Nice one! Thanks!

@odmro
Copy link

odmro commented Dec 28, 2021

convert -alpha remove FILENAME.png FILENAME.svg

For all files in directory:
for i in *.png ; do convert -alpha remove "$i" $(echo $i | sed s/png/svg/) ; done

@MaydayGD
Copy link

MaydayGD commented Jan 18, 2022

Hi, I am trying to convert multiple full-colored PNG to SVG. I use PC. I have Potrace and Inkscape installed. What do I need to do to get this to work on my computer? What does "make it executable" mean? Thank you.

@AntumDeluge
Copy link

AntumDeluge commented Jan 21, 2022

Hi, I am trying to convert multiple full-colored PNG to SVG. I use PC. I have Potrace and Inkscape installed. What do I need to do to get this to work on my computer? What does "make it executable" mean? Thank you.

This is a shell script for Unix/Linux/Posix systems. "make it executable" means doing the following:

$ chmod +x png2svg.sh

If you are on a Windows system, it doesn't mean anything as Windows filesystem doesn't support setting executable bit.

Windows doesn't have a Posix shell. So you won't be able to use this script unless you have an environment like MSYS2 or Cygwin installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment