Last active
August 20, 2025 21:37
-
-
Save agarzola/cf497da7fbc3720f7859e6516a51d5c2 to your computer and use it in GitHub Desktop.
A very naive script that converts any SVGs in the current directory into PNGs using the rsvg-convert tool. Requires installing librsvg (brew install librsvg).
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
| #!/bin/zsh | |
| # Convert all SVG files in current directory to PNG using librsvg. | |
| for svg_file in *.svg; do | |
| # Check that this is in fact an SVG file. | |
| if [[ ! -f "$svg_file" ]]; then | |
| echo "$svg_file is not an SVG file" | |
| continue | |
| fi | |
| # Get filename without extension. | |
| base_name="${svg_file:r}" | |
| # Run rsvg-convert command. | |
| echo "Converting: $svg_file -> ${base_name}.png" | |
| rsvg-convert --width 1024 --keep-aspect-ratio "$svg_file" --output "${base_name}.png" | |
| # Check if conversion was successful. | |
| if [[ $? -eq 0 ]]; then | |
| echo "✓ Successfully converted $svg_file" | |
| else | |
| echo "✗ Failed to convert $svg_file" | |
| fi | |
| done | |
| echo "Conversion complete!" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@apotek Good point. I updated the script to echo a more useful message and also to
continueinstead ofbreakin such a case.Thanks for the feedback!