Skip to content

Instantly share code, notes, and snippets.

@and-rom
Last active January 15, 2019 10:15
Show Gist options
  • Save and-rom/ef71133a32814252a879ab3483428b08 to your computer and use it in GitHub Desktop.
Save and-rom/ef71133a32814252a879ab3483428b08 to your computer and use it in GitHub Desktop.
Telegram Desktop icons generator
#!/bin/bash
# Telegram Desktop icons generator
#
# Requirements:
# - Imagemagic
# - Inkscape
# - Font Roboto Bold
#
# Inatalation:
# cd ~/.local/share/TelegramDesktop/tdata
# git init
# git remote add origin https://gist.github.com/and-rom/ef71133a32814252a879ab3483428b08
# git fetch
# git checkout -t origin/master
#
# Usage:
# ./telegram-systray-icons.sh [FROM] [TO]
# FROM
# Set the value from which to start generation. If value is 0 then icons with arrow will be generated. Default value is 0.
# TO
# Set the value on which generation will end. Default value is 999.
[ -z $1 ] && from=0 || from=$1
[ -z $2 ] && to=999 || to=$2
mkdir -p ./tmp
make_arrow () {
cat <<EOF >./tmp/arrow.svg
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="220"
height="220"
viewBox="0 0 220 220">
<path
style="fill:#ff0000"
d="m 155.06342,55 c 2.55902,-0.143 5.14237,0.818125 7.11673,2.7929 2.63257,2.632575 3.41784,6.29915 2.25583,9.614275 L 127.59037,172.49265 c -2.73845,7.80134 -13.52381,8.45941 -17.1875,1.04775 L 89.240662,130.70585 46.40625,109.57072 C 38.994175,105.90704 39.651838,95.121675 47.454,92.383225 L 152.53947,55.510537 c 0.82913,-0.290125 1.67145,-0.462 2.52437,-0.510125 z" />
</svg>
EOF
inkscape -z -e ./tmp/arrow.png ./tmp/arrow.svg
}
for n in {1..2}
do
case $n in
"1")
color="#ccccccff"
name="icon"
;;
"2")
color="#474747ff"
name="iconmute"
;;
esac
convert -size 220x220 xc:none -fill "$color" -draw "circle 110,110 210,110" ./tmp/circle.png
if [[ $n -eq 1 && $from -eq 0 ]]
then
make_arrow
composite -compose Dst_Out -gravity center ./tmp/arrow.png ./tmp/circle.png -alpha Set "./tmp/icon_22_0.png"
composite -compose Dst_Out -gravity center ./tmp/arrow.png ./tmp/circle.png -alpha Set "./tmp/iconmute_22_0.png"
(( from++ ))
fi
for i in $(eval echo "{$from..$to}")
do
if [ $i -ge 1000 ]
then
size=85
elif [ $i -ge 100 ]
then
size=95
else
size=135
fi
if [ $i -ge 1000 ]
then
text=".."${i: -2}
else
text=$i
fi
convert -size 220x220 -background none -fill red -gravity center -font Roboto-Bold -pointsize $size label:"$text" ./tmp/text.png
composite -compose Dst_Out -gravity center ./tmp/text.png ./tmp/circle.png -alpha Set "./tmp/"$name"_22_"$i".png"
done
done
mkdir -p ./ticons
mogrify -path ./ticons -resize 10x10% ./tmp/icon*.png
rm -rf ./tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment