Last active
April 28, 2020 08:28
-
-
Save sathishvj/d080f6286876ea2de741dda1a3b0756f to your computer and use it in GitHub Desktop.
shell script to convert svg to pngs in many colors (uses inkscape)
This file contains 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
#!/bin/bash | |
# i had a specific requirement to convert icons at iconmonstr.com to all google colors for my slides for youtube.com/AwesomeGCP | |
# doing it manually on their site was cumbersome. | |
# so it is very specific to simple svgs | |
endSvgRgx="\.svg$" | |
# for each input file | |
for file in $* | |
do | |
# does the file exist? | |
if [ ! -f "$file" ]; then | |
echo "File not found: $file" | |
exit 1 | |
fi | |
# does it end in svg? | |
if [[ ! $file =~ $endSvgRgx ]]; then | |
echo "File does not end in .svg: $file" | |
exit 1 | |
fi | |
declare -a colors=("#4285F4" "#DB4437" "#F4B400" "#0F9D58" "#566573" "#D5D8DC" "#FFFFFF") | |
declare -a colorNames=("google-blue" "google-red" "google-yellow" "google-green" "dark-grey" "light-grey" "white") | |
# for eacch color | |
for i in "${!colors[@]}"; do | |
color="${colors[$i]}" | |
colorName="${colorNames[$i]}" | |
tmpFile="tmp-$colorName-$file" | |
# add the color to a temporary svg | |
sed -e 's/<path d="/<path fill='"\"$color\""' d="/g' $file > "$tmpFile" | |
pngName=$(echo "$file" | sed "s/.svg/-$colorName.png/") | |
# convert the | |
# i wrote this with Inkscape 1.0rc1 (09960d6, 2020-04-09) | |
inkscape --export-filename="$pngName" -h 1000 -w 1000 "$tmpFile" | |
# inkscape --export-filename="$pngName" -h 1000 "$tmpFile" #seems to proportionally scale the image | |
# remove temporary svg file | |
rm "$tmpFile" | |
done | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment