Merge branch 'hotfix/21.56.9' into master
[gitter.git] / build-scripts / compress-images.sh
blob03a0e8e92594e340e1756825ddbad498343ad0f9
1 #!/usr/bin/env bash
3 set -euo pipefail
4 IFS=$'\n\t'
6 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8 compress_dir() {
9 shopt -s nullglob
10 local dir_name=$1
11 pushd . > /dev/null
12 cd ${dir_name}
13 pwd
15 for i in *.png; do
16 local input=${i}
17 local output=$(mktemp)
18 local starts_with_dash=0
19 local tmp_file_name=""
21 # zopfli freaks out for things that start with a dash, so we need to
22 # copy them first
23 if [[ ${input} = -* ]]; then
24 starts_with_dash=1
25 tmp_file_name=$(mktemp)
26 cp -- ${input} ${tmp_file_name}
27 input=${tmp_file_name}
30 zopflipng -m --iterations=15 --filters=0meb ${input} ${output}
31 if [[ -f ${output} ]]; then
32 mv -- "${output}" "${i}"
35 if [[ -n ${tmp_file_name} ]]; then
36 rm -f ${tmp_file_name};
39 rm -f ${output}
40 done
42 popd
46 if [[ -n ${1} ]]; then
47 compress_dir ${1}
48 exit
51 for i in $(find "${SCRIPT_DIR}/../public" -name '*.png' -exec dirname {} \;|sort -ur); do
52 compress_dir ${i}
53 done