-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from symflower/convert-svg-to-png
Script to convert all SVG files to PNG with Inkscape
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
# Function to generate a clean, lowercase filename | ||
clean_filename() { | ||
echo "$1" | \ | ||
tr '[:upper:]' '[:lower:]' | \ | ||
sed -e 's/[^[:alnum:][:space:]-]/ /g' | \ | ||
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | \ | ||
sed -e 's/[[:space:]]\+/-/g' | ||
} | ||
|
||
# Loop through all SVG files in the current directory | ||
for svg_file in *.svg *.SVG; do | ||
# Check if the file exists (in case no SVG files are found) | ||
[ -e "$svg_file" ] || continue | ||
|
||
# Generate the new SVG filename | ||
new_svg_name=$(clean_filename "${svg_file%.svg}").svg | ||
|
||
# Rename the SVG file if the new name is different | ||
if [ "$svg_file" != "$new_svg_name" ]; then | ||
mv "$svg_file" "$new_svg_name" | ||
echo "Renamed $svg_file to $new_svg_name" | ||
fi | ||
|
||
# Generate the PNG filename | ||
png_file=$(clean_filename "${svg_file%.svg}").png | ||
|
||
# Convert SVG to PNG using Inkscape | ||
inkscape --export-type=png \ | ||
--export-filename="$png_file" \ | ||
--export-width=3600 \ | ||
"$new_svg_name" | ||
|
||
echo "Converted $new_svg_name to $png_file" | ||
done | ||
|
||
echo "Renaming and conversion complete!" |