Last active
March 9, 2021 11:09
-
-
Save ilyar/fd5e109924b2cb3feed80fb1fe596495 to your computer and use it in GitHub Desktop.
Convert png to svg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Install | |
| # wget https://git.io/JqtZd -O ~/.local/bin/png2svg && chmod +x ~/.local/bin/png2svg | |
| if [ "$1" == "" ]; then | |
| echo "Usage: $0 png file" | |
| exit 0; | |
| fi | |
| filename=$(basename "$1" .png) | |
| if [ ! -e "$filename.png" ]; then | |
| echo "$filename.png does not exist" | |
| exit 1; | |
| fi | |
| width=$(identify -format '%w' "$filename.png") | |
| height=$(identify -format '%h' "$filename.png") | |
| base64=$(cat "$filename.png" | base64 -w0) | |
| image=$(printf '<image width="%s" height="%s" preserveAspectRatio="none" style="image-rendering:optimizeQuality" xlink:href="data:image/png;base64,%s"/>' "$width" "$height" "$base64") | |
| printf '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="%s" height="%s">%s</svg>' "$width" "$height" "$image" > "$filename.svg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment