Convert .svg to .png and change the color and background
Introduction
Before reading this article, make sure that you are familiar with the content of the article «Bash Basics»
Convert .svg to .png
Let us name the script for converting .svg to .png list_sites.sh
#!/bin/bash OLD_EXT=svg NEW_EXT=png DOT="." NEW_COLOR=E80FE3 NEW_BG=lightblue PATTERN1="s@stroke\=\"#000000\"@stroke\=\"#$NEW_COLOR\"@" PATTERN2="s@fill\=\"#000000\"@fill\=\"#$NEW_COLOR\"@" for file in ./*; do EXT="${file##*.}" if [[ $EXT = "svg" ]]; then # with extension fullname="${file##/}" # e.g. ./IMAGE.svg # echo "fullname" # echo $fullname # without extension filename="${file%.*}" # e.g. ./IMAGE echo "filename" echo $filename new_file=$filename$DOT$NEW_EXT echo $new_file if test -f "$new_file"; then echo "$(date '+%Y-%m-%d %H:%M:%S,%3N')" ____ "\ $new_file exists" >> convert_to_png.log else echo "$(date '+%Y-%m-%d %H:%M:%S,%3N')" ____ "\ Converting $file to $new_file" >> convert_to_png.log sed -i $PATTERN1 $fullname sed -i $PATTERN2 $fullname # sed -i 's@stroke\="#000000"@stroke\="#E80FE3"@' $fullname # sed -i 's@fill\="#000000"@fill\="#E80FE3"@' $fullname inkscape -b lightblue $fullname --export-type=png --export-filename=$new_file # mv $fullname $new_file fi fi done
Article author: Andrei Olegovich