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
Lukas Winkler d933c3d840 add icons for referrers (searchEngines and socials)
TODO: Parse html to find favicon in custom path
2016-12-23 14:23:20 +01:00

55 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
shopt -s globstar
size=16
for i in src/**/*.{png,gif,jpg,ico}; do
echo "$i"
absDirname=$(dirname "$i")
origFilename=$(basename "$i")
code=${origFilename%.*}
dirname="dist/${absDirname#src/}"
distFile="${dirname}/${code}.png"
echo "$distFile"
if [ ! -d "$dirname" ]
then
mkdir -p "$dirname"
fi
if [[ $i == *.ico ]]
then
if file "$i" | grep -E "HTML|empty| data" # 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
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:
optipng -o 9 -q "$distFile"
echo ""
done