File: optimizegraphics

package info (click to toggle)
kdesdk 4%3A4.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 35,784 kB
  • ctags: 23,382
  • sloc: cpp: 213,702; xml: 87,019; perl: 14,567; lisp: 6,813; sh: 2,708; ansic: 2,015; python: 1,952; ruby: 1,593; makefile: 15; sed: 9
file content (47 lines) | stat: -rwxr-xr-x 1,750 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh

# Copyright 2008 Urs Wolfer <uwolfer @ kde.org>
# 
# 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 2 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.
# 
#
# Thin wrapper script around optipng and advdef.
# It filters the output and shows a summary at the end of the optimization run.
# Tested with:
# * OptiPNG 0.5.5 http://optipng.sourceforge.net/
# * advdef (AdvanceCOMP) 1.15 http://advancemame.sourceforge.net/comp-readme.html


if test "$1" = "-h" -o "$1" = "--help"; then
    echo "Usage: optimizegraphics [FILE]";
    echo "If [FILE] is not defined, it optimizes all files recursively starting at the current working directory.";
    exit;
fi

if [ $# -ne 0 ]; then # file is defined
    optipng -o5 "$1";
    advdef -z -4 "$1";
exit;
else # do it recursively
    STARTSIZE=`du -s | awk '{ print $1 }'`;

    find . -name "*.png" -exec optipng -o5 '{}' \; -print | grep 'Processing\|already\|% decrease';
    find . -name "*.png" -exec advdef -z -4 '{}' \; -print | grep '% ./';
 
    find . -name "*.svgz" -exec advdef -z -4 '{}' \; -print | grep '% ./';

    ENDSIZE=`du -s | awk '{ print $1 }'`;

    REDUCEDSIZE=$(($STARTSIZE-$ENDSIZE));

    echo "optimizegraphics: Losslessly optimized PNG and SVGZ files with \"optipng -o5\" and \"advdef -z -4\".";
    echo "Reduced disk space:" $REDUCEDSIZE"KB ("$(($REDUCEDSIZE/1024))"MB)";
fi