Created a very basic/hacky script to update the svgs with viewboxes.
The script uses inkscape to query for the proper size and then rounds those to the nearest integer and hacks them into the .svg.
Initially - I updated all .svg files - even ones with viewboxes. However, I don't think those changes are strictly needed to view in a web browser as changes to existing viewboxes typically just remove some 'padding', but would already display fine. It is possible to comment out the continue in script to update all svg files.
I did not include the script in the repo and just put it below - it's enough of a hack - not sure it belongs in the actual repo or not.
Script
The bash script is as follows - requires inskscape. To run, create the script in the logos directory and run it with bash. Ex bash ./update-viewbox.sh. You should be able to run it multiple times and it won't hurt anything.
NOTE: this script requires linux (tested on Ubuntu 20.04). It probably could be adapted to run on a mac if needed/desired (would need changes like: sed -i bak instead of sed -i, etc, but should be pretty simple - just let me know)
#! /bin/bash
set -e
for file in *.svg; do
echo "file: $file"
if ! grep viewBox "$file"; then
echo "adding default viewBox"
sed -i 's|xmlns=|viewBox="" xmlns=|g' "$file"
else
echo "viewbox exists"
# comment the below line (`continue`) to update .svg's with existing viewBox attributes
continue
#If a viewBox attribute starts somewhere other than 0,0, it will mess up the calculation. So just remove a viewbox and recalculate
echo "viewbox already set in $file - resetting"
sed -i "s|viewBox=\"[0-9 ]*\"|viewBox=\"\"|g" "$file"
fi
RAW_LINE="$(inkscape --query-all "$file" 2>/dev/null | head -1)"
X1="$(echo "$RAW_LINE" | cut -d',' -f2| awk '{print int($1+0.5)}' )"
Y1="$(echo "$RAW_LINE" | cut -d',' -f3| awk '{print int($1+0.5)}')"
X2="$(echo "$RAW_LINE" | cut -d',' -f4| awk '{print int($1+0.5)}')"
Y2="$(echo "$RAW_LINE" | cut -d',' -f5| awk '{print int($1+0.5)}')"
echo "raw: $RAW_LINE"
echo "x1: $X1 y1: $Y1 x2: $X2 y2: $Y2"
echo "updating viewBox"
sed -i "s|viewBox=\"[0-9 ]*\"|viewBox=\"$X1 $Y1 $X2 $Y2\"|g" $file
done
Details
continue
in script to update all svg files.Script
The bash script is as follows - requires
inskscape
. To run, create the script in the logos directory and run it with bash. Exbash ./update-viewbox.sh
. You should be able to run it multiple times and it won't hurt anything.NOTE: this script requires linux (tested on Ubuntu 20.04). It probably could be adapted to run on a mac if needed/desired (would need changes like:
sed -i bak
instead ofsed -i
, etc, but should be pretty simple - just let me know)