]> git.wh0rd.org Git - chrome-ext/clearhistory-advance-fork.git/blob - dist/pngcrush.sh
update dist helpers
[chrome-ext/clearhistory-advance-fork.git] / dist / pngcrush.sh
1 #!/bin/bash -xe
2 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 size()
7 {
8   stat -c %s "$@"
9 }
10
11 do_apngopt()
12 {
13   local png new
14
15   for png in "$@"; do
16     new="${png}.new"
17     apngopt "${png}" "${new}"
18     if [[ $(size "${png}") -gt $(size "${new}") ]]; then
19       mv "${new}" "${png}"
20     else
21       rm "${new}"
22     fi
23   done
24 }
25
26 do_pngcrush()
27 {
28   local png new
29
30   pngcrush -e .png.new "$@"
31   for png in "$@"; do
32     new="${png}.new"
33     mv "${new}" "${png}"
34   done
35 }
36
37 main()
38 {
39   if [ $# -eq 0 ]; then
40     set -- $(find -name '*.png')
41   fi
42
43   if type -P apngopt >/dev/null; then
44     # apngopt likes to corrupt images.
45     : do_apngopt "$@"
46   elif type -P pngcrush >/dev/null; then
47     do_pngcrush "$@"
48   else
49     echo "error: could not find apngopt or pngcrush"
50     exit 1
51   fi
52 }
53 main "$@"