2016-12-21 15:10:23 +01:00
|
|
|
#!/bin/bash
|
|
|
|
shopt -s globstar
|
|
|
|
|
2016-12-23 14:23:20 +01:00
|
|
|
for i in src/**/*.{png,gif,jpg,ico}; do
|
2017-01-21 12:06:13 +01:00
|
|
|
size=48
|
2016-12-21 15:10:23 +01:00
|
|
|
absDirname=$(dirname "$i")
|
|
|
|
origFilename=$(basename "$i")
|
2016-12-23 14:23:20 +01:00
|
|
|
code=${origFilename%.*}
|
2016-12-21 15:10:23 +01:00
|
|
|
dirname="dist/${absDirname#src/}"
|
2016-12-23 14:23:20 +01:00
|
|
|
distFile="${dirname}/${code}.png"
|
2016-12-21 15:10:23 +01:00
|
|
|
if [ ! -d "$dirname" ]
|
|
|
|
then
|
|
|
|
mkdir -p "$dirname"
|
|
|
|
fi
|
2016-12-23 14:23:20 +01:00
|
|
|
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
|
2016-12-23 14:23:20 +01:00
|
|
|
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
|
2017-01-21 12:06:13 +01:00
|
|
|
if echo "$i" | grep "SEO" # if SEO image -> 72px(https://github.com/piwik/piwik/pull/11234)
|
|
|
|
then
|
|
|
|
size=72
|
|
|
|
fi
|
2016-12-26 18:21:23 +01:00
|
|
|
# if file (or symlink) -> didn't get deleted
|
|
|
|
if [ -e "$i" ]
|
|
|
|
then
|
2017-01-03 10:21:55 +01:00
|
|
|
width=$(identify -ping -format "%w" "$i")
|
|
|
|
height=$(identify -ping -format "%h" "$i")
|
|
|
|
if [[ $height -gt $size ]] && [[ $width -gt $size ]]
|
|
|
|
then
|
|
|
|
convert \
|
|
|
|
"$i" \
|
2017-02-20 09:59:32 +01:00
|
|
|
-fill transparent \
|
|
|
|
-fuzz 1% \
|
|
|
|
-floodfill +0+0 white \
|
|
|
|
-floodfill +"$((width-1))"+0 white \
|
|
|
|
-floodfill +0+"$((height-1))" white \
|
|
|
|
-floodfill +"$((width-1))"+"$((height-1))" white \
|
2017-01-03 10:21:55 +01:00
|
|
|
-strip \
|
|
|
|
-background none \
|
|
|
|
-trim \
|
|
|
|
-thumbnail ${size}x${size}\> \
|
|
|
|
-unsharp 0x1 \
|
|
|
|
-gravity center \
|
|
|
|
-extent ${size}x${size} \
|
|
|
|
"$distFile"
|
|
|
|
# input file
|
|
|
|
# strip metadata
|
2017-02-20 09:59:32 +01:00
|
|
|
# floodfill from every corner
|
2017-01-03 10:21:55 +01:00
|
|
|
# make background transparent
|
|
|
|
# keep transparency
|
|
|
|
# cut border
|
|
|
|
# get only one image from .ico
|
|
|
|
# resize while keeping the aspect ratio
|
|
|
|
# sharpen the image
|
|
|
|
# center image
|
|
|
|
# fit to 16x16
|
|
|
|
else
|
|
|
|
convert \
|
|
|
|
"$i" \
|
|
|
|
-strip \
|
|
|
|
-transparent white \
|
|
|
|
-background none \
|
|
|
|
"$distFile"
|
|
|
|
echo -e "\033[31mWarning: This image is smaller than the default size (${width}x${height})"
|
|
|
|
echo -e "$i"
|
|
|
|
echo -e "\033[0m"
|
|
|
|
fi
|
2016-12-26 18:21:23 +01:00
|
|
|
# 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
|
2017-01-04 10:46:35 +01:00
|
|
|
|
|
|
|
convert --version > versions.txt
|
|
|
|
echo "pngquant version:" >> versions.txt
|
|
|
|
pngquant --version >> versions.txt
|