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!" |
The only case I can think of would be if you had a sub-directory named
subdirectory.svg
, in which case the edge case error message should be "Not a file," not "No svg files".
@apotek Good point. I updated the script to echo a more useful message and also to continue
instead of break
in such a case.
Thanks for the feedback!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting that Claude thinks that the non-existence of a particular file means that no SVG files were found. You kind of don't really need this test at all, since every output of the glob expression can safely be assumed to be a file. (I can't think of a scenario where the match of a glob expression isn't as file or symlink or link. The only case I can think of would be if you had a sub-directory named
subdirectory.svg
, in which case the edge case error message should be "Not a file," not "No svg files".This was interesting to look at. It's really interesting to see the solution patterns that Claude (et al) predict.