2016-12-21 15:10:23 +01:00
|
|
|
#!/bin/bash
|
2017-02-22 10:44:15 +01:00
|
|
|
# Copyright (C) 2017 Lukas Winkler
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-12-21 15:10:23 +01:00
|
|
|
shopt -s globstar
|
2017-04-07 17:19:28 +02:00
|
|
|
set -x
|
|
|
|
set -e
|
2016-12-21 15:10:23 +01:00
|
|
|
|
2017-04-07 17:19:28 +02:00
|
|
|
function resizeLargeIcon () {
|
|
|
|
inputfile=$1
|
|
|
|
outputfile=$2
|
|
|
|
convert \
|
|
|
|
"$inputfile" \
|
2017-06-06 08:35:57 +02:00
|
|
|
-bordercolor white -border 1x1 \
|
2017-04-07 17:19:28 +02:00
|
|
|
-fill transparent \
|
|
|
|
-fuzz 1% \
|
|
|
|
-floodfill +0+0 white \
|
|
|
|
-floodfill +"$((width-1))"+0 white \
|
|
|
|
-floodfill +0+"$((height-1))" white \
|
2017-04-24 17:28:06 +02:00
|
|
|
-floodfill +$((width-1))+$((height-1)) white \
|
2017-04-07 17:19:28 +02:00
|
|
|
-strip \
|
|
|
|
-background none \
|
2017-04-21 09:43:20 +02:00
|
|
|
-fuzz 0 \
|
2017-04-07 17:19:28 +02:00
|
|
|
-trim \
|
2017-04-24 17:28:06 +02:00
|
|
|
-thumbnail "${size}"x"${size}"\> \
|
2017-04-07 17:19:28 +02:00
|
|
|
-unsharp 0x1 \
|
|
|
|
-gravity center \
|
2017-04-24 17:28:06 +02:00
|
|
|
-extent "${size}"x"${size}" \
|
2017-04-07 17:19:28 +02:00
|
|
|
"$outputfile"
|
|
|
|
# input file
|
|
|
|
# strip metadata
|
|
|
|
# floodfill from every corner
|
|
|
|
# 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
|
2017-04-24 17:28:06 +02:00
|
|
|
optimizeIcon "$outputfile"
|
2017-04-07 17:19:28 +02:00
|
|
|
}
|
|
|
|
function resizeSmallIcon () {
|
|
|
|
inputfile=$1
|
|
|
|
outputfile=$2
|
|
|
|
convert \
|
|
|
|
"$inputfile" \
|
|
|
|
-strip \
|
|
|
|
-transparent white \
|
|
|
|
-background none \
|
|
|
|
"$outputfile"
|
|
|
|
echo -e "\033[31mWarning: This image is smaller than the default size (${width}x${height})"
|
|
|
|
echo -e "$inputfile"
|
|
|
|
echo -e "\033[0m"
|
2017-04-24 17:28:06 +02:00
|
|
|
optimizeIcon "$outputfile"
|
2017-04-07 17:19:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function resizeSvg () {
|
|
|
|
inputfile=$1
|
|
|
|
outputfile=$2
|
2017-04-19 22:02:45 +02:00
|
|
|
if echo "$outputfile" | grep "flags"
|
|
|
|
then
|
2017-04-24 17:28:06 +02:00
|
|
|
inkscape -f "$inputfile" -h "$size" -e "$outputfile"
|
2017-04-19 22:02:45 +02:00
|
|
|
else
|
|
|
|
inkscape -f "$inputfile" -h 1024 -e "$outputfile"
|
|
|
|
mogrify \
|
|
|
|
-background none \
|
2017-06-06 08:35:57 +02:00
|
|
|
-bordercolor transparent -border 1x1 \
|
2017-04-19 22:02:45 +02:00
|
|
|
-trim \
|
2017-04-24 17:28:06 +02:00
|
|
|
-thumbnail "${size}"x"${size}"\> \
|
2017-04-19 22:02:45 +02:00
|
|
|
-unsharp 0x1 \
|
|
|
|
-gravity center \
|
2017-04-24 17:28:06 +02:00
|
|
|
-extent "${size}"x"${size}" \
|
2017-04-19 22:02:45 +02:00
|
|
|
"$outputfile"
|
|
|
|
|
|
|
|
fi
|
2017-04-24 17:28:06 +02:00
|
|
|
optimizeIcon "$outputfile"
|
2017-04-07 17:19:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function optimizeIcon () {
|
|
|
|
pngquant -f --ext .png -s 1 --skip-if-larger --quality 70-95 "$1" || [ $? -gt 97 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleMultisizeIco () {
|
|
|
|
file=$1
|
|
|
|
code=$2
|
|
|
|
if file "$file" | grep -E "HTML|empty|ASCII text|: data|SVG" # if no valid image
|
2016-12-23 14:23:20 +01:00
|
|
|
then
|
2017-04-07 17:19:28 +02:00
|
|
|
rm "$file"
|
|
|
|
else
|
|
|
|
if [ ! -d "tmp" ]
|
2016-12-23 14:23:20 +01:00
|
|
|
then
|
2017-04-07 17:19:28 +02:00
|
|
|
mkdir "tmp"
|
2016-12-23 14:23:20 +01:00
|
|
|
fi
|
2017-04-07 17:19:28 +02:00
|
|
|
largestIcon=$(python analyseIco.py "$1")
|
|
|
|
newIcon="tmp/${code}.ico"
|
2017-04-24 17:28:06 +02:00
|
|
|
convert "${i}"\["$largestIcon"\] "$newIcon"
|
|
|
|
echo "$newIcon" # "return"
|
2016-12-23 14:23:20 +01:00
|
|
|
fi
|
2017-04-07 17:19:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function fixFlags () {
|
2017-04-24 17:28:06 +02:00
|
|
|
height="$1"
|
2017-04-07 17:19:28 +02:00
|
|
|
targetDir="dist/flags"
|
|
|
|
resizeSvg "unk.flag.svg" "dist/flags/xx.png"
|
|
|
|
|
|
|
|
for i in ac cp dg ea eu fx ic su ta uk an bu cs nt sf tp yu zr a1 a2 ap o1 cat
|
|
|
|
do
|
|
|
|
icon="${targetDir}/${i}.png"
|
|
|
|
if [ ! -f "$icon" ]
|
2017-01-03 10:21:55 +01:00
|
|
|
then
|
2017-04-07 17:19:28 +02:00
|
|
|
echo -e "\033[31mWarning: No flag for $i, using default\033[0m"
|
|
|
|
cp "dist/flags/xx.png" "$icon"
|
2017-01-03 10:21:55 +01:00
|
|
|
fi
|
2017-04-07 17:19:28 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
rm ${targetDir}/gb-*
|
|
|
|
rm ${targetDir}/un.png
|
2017-06-28 10:44:01 +02:00
|
|
|
rm ${targetDir}/es-ct.png
|
2017-04-07 17:19:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function loopThrough () {
|
|
|
|
for i in src/**/*.{svg,png,gif,jpg,ico}; do
|
|
|
|
size=48
|
|
|
|
absDirname=$(dirname "$i")
|
|
|
|
origFilename=$(basename "$i")
|
|
|
|
code=${origFilename%.*}
|
|
|
|
dirname="dist/${absDirname#src/}"
|
|
|
|
distFile="${dirname}/${code}.png"
|
|
|
|
if [ ! -d "$dirname" ]
|
|
|
|
then
|
|
|
|
mkdir -p "$dirname"
|
|
|
|
fi
|
|
|
|
if [[ $i == *.ico ]]
|
|
|
|
then
|
2017-04-24 17:28:06 +02:00
|
|
|
i=$(handleMultisizeIco "$i" "$code")
|
2017-04-07 17:19:28 +02:00
|
|
|
fi
|
|
|
|
if echo "$i" | grep "SEO" # if SEO image -> 72px(https://github.com/piwik/piwik/pull/11234)
|
|
|
|
then
|
|
|
|
size=72
|
|
|
|
fi
|
|
|
|
if [[ $i == *.svg ]]
|
|
|
|
then
|
2017-04-24 17:28:06 +02:00
|
|
|
resizeSvg "$i" "$distFile"
|
2017-04-07 17:19:28 +02:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
# if file (or symlink) -> didn't get deleted
|
|
|
|
if [ -e "$i" ]
|
|
|
|
then
|
|
|
|
width=$(identify -ping -format "%w" "$i")
|
|
|
|
height=$(identify -ping -format "%h" "$i")
|
|
|
|
if [[ $height -gt $size ]] && [[ $width -gt $size ]]
|
|
|
|
then
|
2017-04-24 17:28:06 +02:00
|
|
|
resizeLargeIcon "$i" "$distFile"
|
2017-04-07 17:19:28 +02:00
|
|
|
else
|
2017-04-24 17:28:06 +02:00
|
|
|
resizeSmallIcon "$i" "$distFile"
|
2017-04-07 17:19:28 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveVersions () {
|
2017-04-24 17:28:06 +02:00
|
|
|
{
|
|
|
|
convert --version
|
|
|
|
echo "pngquant version:"
|
|
|
|
pngquant --version
|
|
|
|
inkscape --version
|
|
|
|
} > versions.txt
|
2017-04-07 17:19:28 +02:00
|
|
|
}
|
|
|
|
function main () {
|
|
|
|
loopThrough
|
|
|
|
fixFlags 48
|
|
|
|
saveVersions
|
|
|
|
}
|
2017-01-04 10:46:35 +01:00
|
|
|
|
2017-04-07 17:19:28 +02:00
|
|
|
main
|