1
0
Fork 0
mirror of https://github.com/matomo-org/matomo-icons.git synced 2024-09-19 17:03:45 +02:00
matomo-icons/convert.sh

59 lines
1.5 KiB
Bash
Raw Normal View History

2016-12-21 15:10:23 +01:00
#!/bin/bash
shopt -s globstar
size=16
for i in src/**/*.{png,gif,jpg,ico}; do
2016-12-21 15:10:23 +01:00
echo "$i"
absDirname=$(dirname "$i")
origFilename=$(basename "$i")
code=${origFilename%.*}
2016-12-21 15:10:23 +01:00
dirname="dist/${absDirname#src/}"
distFile="${dirname}/${code}.png"
2016-12-21 15:10:23 +01:00
echo "$distFile"
if [ ! -d "$dirname" ]
then
mkdir -p "$dirname"
fi
if [[ $i == *.ico ]]
then
2016-12-26 18:21:23 +01:00
if file "$i" | grep -E "HTML|empty|ASCII text|: data|SVG" # if no valid image
then
rm "$i"
else
if [ ! -d "tmp" ]
then
mkdir "tmp"
fi
largestIcon=$(python analyseIco.py "$i")
newIcon="tmp/${code}.ico"
convert ${i}\[$largestIcon\] $newIcon
i=$newIcon
fi
fi
2016-12-26 18:21:23 +01:00
# if file (or symlink) -> didn't get deleted
if [ -e "$i" ]
then
convert \
"$i" \
-strip \
-transparent white \
-background none \
-trim \
-resize ${size}x${size} \
-gravity center \
-extent ${size}x${size} \
"$distFile"
# input file
# strip metadata
# make background transparent
# keep transparency
# cut border
# get only one image from .ico
# resize while keeping the aspect ratio
# center image
# fit to 16x16
# optimize png:
pngquant -f --ext .png -s 1 --skip-if-larger --quality 70-95 "$distFile"
fi
2016-12-21 15:10:23 +01:00
done