0
0
mirror of https://github.com/markusfisch/BinaryEye.git synced 2024-09-20 12:02:17 +02:00
BinaryEye/svg/update.sh

120 lines
2.0 KiB
Bash
Raw Normal View History

2017-08-27 15:03:22 +02:00
#!/usr/bin/env bash
# Try to find Inkscape or ImageMagick's convert
find_converter() {
2017-08-27 15:03:22 +02:00
if [ -z "$INKSCAPE" ]
then
INKSCAPE=$(which inkscape) ||
2020-03-31 20:10:52 +02:00
INKSCAPE='/Applications/Inkscape.app/Contents/MacOS/Inkscape'
2017-08-27 15:03:22 +02:00
fi
if [ -x "$INKSCAPE" ]
then
converter() {
2017-08-27 15:03:22 +02:00
"$INKSCAPE" \
"$PWD/$1" \
2020-03-31 20:10:52 +02:00
-o "$PWD/$2" \
2017-08-27 15:03:22 +02:00
-w "$3" \
-h "$4"
2017-08-27 15:03:22 +02:00
}
elif which convert &>/dev/null
then
converter() {
2017-08-27 15:03:22 +02:00
convert \
-background none \
"$1" \
-thumbnail "${3}x${4}" \
2017-08-27 15:03:22 +02:00
-strip \
"$2"
}
else
return 1
fi
}
# Scale a length and cut off fraction
2017-08-27 15:03:22 +02:00
#
# @param 1 - length
# @param 2 - multiplier
scale() {
echo "$1*$2" | bc -l | cut -d '.' -f 1
}
2017-08-27 15:03:22 +02:00
# Make sure $DIR exists
check_dir() {
[ -d "$DIR" ] || mkdir -p "$DIR" || {
echo "error: couldn't create $DIR" >&2
return $?
2017-08-27 15:03:22 +02:00
}
}
2017-08-27 15:03:22 +02:00
# Returns true if source is older than target file
#
# @param 1 - target file
# @param 2 - source file
newer_than() {
[ -r "$1" ] && [ -z "$(find "$2" -type f -newer "$1")" ]
}
2017-08-27 15:03:22 +02:00
# Convert SVG files in multiple resolutions to PNG
#
# @param 1 - output path
update() {
local SVG SIZE NEGATE
2017-08-27 15:03:22 +02:00
while read -r SVG SIZE NEGATE
do
SIZE=${SIZE:-24}
local DPI MULTIPLIER DIR PNG
2017-08-27 15:03:22 +02:00
while read -r DPI MULTIPLIER
do
DIR="$1-$DPI"
check_dir || return $?
2017-08-27 15:03:22 +02:00
PNG=${SVG##*/}
PNG="$DIR/${PNG%.*}.png"
newer_than "$PNG" "$SVG" && continue
2017-08-27 15:03:22 +02:00
converter \
"$SVG" \
"$PNG" \
"$(scale "${SIZE%%x*}" "$MULTIPLIER")" \
"$(scale "${SIZE##*x}" "$MULTIPLIER")"
2017-08-27 15:03:22 +02:00
if (( NEGATE ))
then
convert "$PNG" -negate "$PNG"
fi
done <<EOF
xxxhdpi 4
xxhdpi 3
xhdpi 2
hdpi 1.5
mdpi 1
ldpi .75
EOF
done
}
type converter &>/dev/null || find_converter || {
echo "error: no Inkscape and no ImageMagick convert" >&2
exit 1
2017-08-27 15:03:22 +02:00
}
update app/src/debug/res/mipmap << EOF
svg/debug/ic_launcher.svg 48
EOF
2017-08-27 15:03:22 +02:00
update app/src/main/res/mipmap << EOF
svg/ic_launcher.svg 48
EOF
update app/src/main/res/drawable << EOF
svg/ic_shortcut_decode.svg 48
svg/ic_shortcut_encode.svg 48
svg/ic_shortcut_preferences.svg 48
2018-04-30 11:01:54 +02:00
svg/logo.svg 80
svg/wallpaper.svg 384
EOF