Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(549)

Side by Side Diff: tools/resources/optimize-png-files.sh

Issue 60733028: Make output concise by default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Further cleanup console output Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # The optimization code is based on pngslim (http://goo.gl/a0XHg) 6 # The optimization code is based on pngslim (http://goo.gl/a0XHg)
7 # and executes a similar pipleline to optimize the png file size. 7 # and executes a similar pipleline to optimize the png file size.
8 # The steps that require pngoptimizercl/pngrewrite/deflopt are omitted, 8 # The steps that require pngoptimizercl/pngrewrite/deflopt are omitted,
9 # but this runs all other processes, including: 9 # but this runs all other processes, including:
10 # 1) various color-dependent optimizations using optipng. 10 # 1) various color-dependent optimizations using optipng.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 # Global variables for stats 43 # Global variables for stats
44 TOTAL_OLD_BYTES=0 44 TOTAL_OLD_BYTES=0
45 TOTAL_NEW_BYTES=0 45 TOTAL_NEW_BYTES=0
46 TOTAL_FILE=0 46 TOTAL_FILE=0
47 PROCESSED_FILE=0 47 PROCESSED_FILE=0
48 48
49 declare -a THROBBER_STR=('-' '\\' '|' '/') 49 declare -a THROBBER_STR=('-' '\\' '|' '/')
50 THROBBER_COUNT=0 50 THROBBER_COUNT=0
51 51
52 SUBPROCESS=0
53
54 # NoOp in subprocess, echo otherwise.
55 function info {
56 if [ $SUBPROCESS -eq 0 ]; then
57 echo $@
58 fi
59 }
60
52 # Show throbber character at current cursor position. 61 # Show throbber character at current cursor position.
53 function throbber { 62 function throbber {
54 echo -ne "${THROBBER_STR[$THROBBER_COUNT]}\b" 63 info -ne "${THROBBER_STR[$THROBBER_COUNT]}\b"
55 let THROBBER_COUNT=($THROBBER_COUNT+1)%4 64 let THROBBER_COUNT=($THROBBER_COUNT+1)%4
56 } 65 }
57 66
58 # Usage: pngout_loop <file> <png_out_options> ... 67 # Usage: pngout_loop <file> <png_out_options> ...
59 # Optimize the png file using pngout with the given options 68 # Optimize the png file using pngout with the given options
60 # using various block split thresholds and filter types. 69 # using various block split thresholds and filter types.
61 function pngout_loop { 70 function pngout_loop {
62 local file=$1 71 local file=$1
63 shift 72 shift
64 local opts=$* 73 local opts=$*
65 if [ $OPTIMIZE_LEVEL == 1 ]; then 74 if [ $OPTIMIZE_LEVEL == 1 ]; then
66 for j in $(seq 0 5); do 75 for j in $(seq 0 5); do
67 throbber 76 throbber
68 pngout -q -k1 -s1 -f$j $opts $file 77 pngout -q -k1 -s1 -f$j $opts $file
69 done 78 done
70 else 79 else
71 for i in 0 128 256 512; do 80 for i in 0 128 256 512; do
72 for j in $(seq 0 5); do 81 for j in $(seq 0 5); do
73 throbber 82 throbber
74 pngout -q -k1 -s1 -b$i -f$j $opts $file 83 pngout -q -k1 -s1 -b$i -f$j $opts $file
75 done 84 done
76 done 85 done
77 fi 86 fi
78 } 87 }
79 88
80 # Usage: get_color_depth_list 89 # Usage: get_color_depth_list
81 # Returns the list of color depth options for current optimization level. 90 # Returns the list of color depth options for current optimization level.
82 function get_color_depth_list { 91 function get_color_depth_list {
83 if [ $OPTIMIZE_LEVEL == 1 ]; then 92 if [ $OPTIMIZE_LEVEL == 1 ]; then
84 echo "-d0" 93 echo "-d0"
msw 2013/11/27 17:14:16 nit: s/echo/info/? Should all remaining 'echo' usa
eustas 2013/11/28 07:57:05 Here echo is used to pass return value. This func
85 else 94 else
86 echo "-d1 -d2 -d4 -d8" 95 echo "-d1 -d2 -d4 -d8"
87 fi 96 fi
88 } 97 }
89 98
90 # Usage: process_grayscale <file> 99 # Usage: process_grayscale <file>
91 # Optimize grayscale images for all color bit depths. 100 # Optimize grayscale images for all color bit depths.
92 # 101 #
93 # TODO(oshima): Experiment with -d0 w/o -c0. 102 # TODO(oshima): Experiment with -d0 w/o -c0.
94 function process_grayscale { 103 function process_grayscale {
95 echo -n "|gray" 104 info -n "|gray"
96 for opt in $(get_color_depth_list); do 105 for opt in $(get_color_depth_list); do
97 pngout_loop $file -c0 $opt 106 pngout_loop $file -c0 $opt
98 done 107 done
99 } 108 }
100 109
101 # Usage: process_grayscale_alpha <file> 110 # Usage: process_grayscale_alpha <file>
102 # Optimize grayscale images with alpha for all color bit depths. 111 # Optimize grayscale images with alpha for all color bit depths.
103 function process_grayscale_alpha { 112 function process_grayscale_alpha {
104 echo -n "|gray-a" 113 info -n "|gray-a"
105 pngout_loop $file -c4 114 pngout_loop $file -c4
106 for opt in $(get_color_depth_list); do 115 for opt in $(get_color_depth_list); do
107 pngout_loop $file -c3 $opt 116 pngout_loop $file -c3 $opt
108 done 117 done
109 } 118 }
110 119
111 # Usage: process_rgb <file> 120 # Usage: process_rgb <file>
112 # Optimize rgb images with or without alpha for all color bit depths. 121 # Optimize rgb images with or without alpha for all color bit depths.
113 function process_rgb { 122 function process_rgb {
114 echo -n "|rgb" 123 info -n "|rgb"
115 for opt in $(get_color_depth_list); do 124 for opt in $(get_color_depth_list); do
116 pngout_loop $file -c3 $opt 125 pngout_loop $file -c3 $opt
117 done 126 done
118 pngout_loop $file -c2 127 pngout_loop $file -c2
119 pngout_loop $file -c6 128 pngout_loop $file -c6
120 } 129 }
121 130
122 # Usage: huffman_blocks <file> 131 # Usage: huffman_blocks <file>
123 # Optimize the huffman blocks. 132 # Optimize the huffman blocks.
124 function huffman_blocks { 133 function huffman_blocks {
125 local file=$1 134 local file=$1
126 echo -n "|huffman" 135 info -n "|huffman"
127 local size=$(stat -c%s $file) 136 local size=$(stat -c%s $file)
128 local min_block_size=$DEFAULT_MIN_BLOCK_SIZE 137 local min_block_size=$DEFAULT_MIN_BLOCK_SIZE
129 local limit_blocks=$DEFAULT_LIMIT_BLOCKS 138 local limit_blocks=$DEFAULT_LIMIT_BLOCKS
130 139
131 if [ $size -gt $LARGE_FILE_THRESHOLD ]; then 140 if [ $size -gt $LARGE_FILE_THRESHOLD ]; then
132 min_block_size=$LARGE_MIN_BLOCK_SIZE 141 min_block_size=$LARGE_MIN_BLOCK_SIZE
133 limit_blocks=$LARGE_LIMIT_BLOCKS 142 limit_blocks=$LARGE_LIMIT_BLOCKS
134 fi 143 fi
135 let max_blocks=$size/$min_block_size 144 let max_blocks=$size/$min_block_size
136 if [ $max_blocks -gt $limit_blocks ]; then 145 if [ $max_blocks -gt $limit_blocks ]; then
137 max_blocks=$limit_blocks 146 max_blocks=$limit_blocks
138 fi 147 fi
139 148
140 for i in $(seq 2 $max_blocks); do 149 for i in $(seq 2 $max_blocks); do
141 throbber 150 throbber
142 pngout -q -k1 -ks -s1 -n$i $file 151 pngout -q -k1 -ks -s1 -n$i $file
143 done 152 done
144 } 153 }
145 154
146 # Usage: random_huffman_table_trial <file> 155 # Usage: random_huffman_table_trial <file>
147 # Try compressing by randomizing the initial huffman table. 156 # Try compressing by randomizing the initial huffman table.
148 # 157 #
149 # TODO(oshima): Try adjusting different parameters for large files to 158 # TODO(oshima): Try adjusting different parameters for large files to
150 # reduce runtime. 159 # reduce runtime.
151 function random_huffman_table_trial { 160 function random_huffman_table_trial {
152 echo -n "|random" 161 info -n "|random"
153 local file=$1 162 local file=$1
154 local old_size=$(stat -c%s $file) 163 local old_size=$(stat -c%s $file)
155 local trials_count=$DEFAULT_RANDOM_TRIALS 164 local trials_count=$DEFAULT_RANDOM_TRIALS
156 165
157 if [ $old_size -gt $LARGE_FILE_THRESHOLD ]; then 166 if [ $old_size -gt $LARGE_FILE_THRESHOLD ]; then
158 trials_count=$LARGE_RANDOM_TRIALS 167 trials_count=$LARGE_RANDOM_TRIALS
159 fi 168 fi
160 for i in $(seq 1 $trials_count); do 169 for i in $(seq 1 $trials_count); do
161 throbber 170 throbber
162 pngout -q -k1 -ks -s0 -r $file 171 pngout -q -k1 -ks -s0 -r $file
163 done 172 done
164 local new_size=$(stat -c%s $file) 173 local new_size=$(stat -c%s $file)
165 if [ $new_size -lt $old_size ]; then 174 if [ $new_size -lt $old_size ]; then
166 random_huffman_table_trial $file 175 random_huffman_table_trial $file
167 fi 176 fi
168 } 177 }
169 178
170 # Usage: final_comprssion <file> 179 # Usage: final_comprssion <file>
171 # Further compress using optipng and advdef. 180 # Further compress using optipng and advdef.
172 # TODO(oshima): Experiment with 256. 181 # TODO(oshima): Experiment with 256.
173 function final_compression { 182 function final_compression {
174 echo -n "|final" 183 info -n "|final"
175 local file=$1 184 local file=$1
176 if [ $OPTIMIZE_LEVEL == 2 ]; then 185 if [ $OPTIMIZE_LEVEL == 2 ]; then
177 for i in 32k 16k 8k 4k 2k 1k 512; do 186 for i in 32k 16k 8k 4k 2k 1k 512; do
178 throbber 187 throbber
179 optipng -q -nb -nc -zw$i -zc1-9 -zm1-9 -zs0-3 -f0-5 $file 188 optipng -q -nb -nc -zw$i -zc1-9 -zm1-9 -zs0-3 -f0-5 $file
180 done 189 done
181 fi 190 fi
182 for i in $(seq 1 4); do 191 for i in $(seq 1 4); do
183 throbber 192 throbber
184 advdef -q -z -$i $file 193 advdef -q -z -$i $file
185 done 194 done
186 echo -ne "\r" 195 info -ne "\r"
187 } 196 }
188 197
189 # Usage: get_color_type <file> 198 # Usage: get_color_type <file>
190 # Returns the color type name of the png file. Here is the list of names 199 # Returns the color type name of the png file. Here is the list of names
191 # for each color type codes. 200 # for each color type codes.
192 # 0 : grayscale 201 # 0 : grayscale
193 # 2 : RGB 202 # 2 : RGB
194 # 3 : colormap 203 # 3 : colormap
195 # 4 : gray+alpha 204 # 4 : gray+alpha
196 # 6 : RGBA 205 # 6 : RGBA
197 # See http://en.wikipedia.org/wiki/Portable_Network_Graphics#Color_depth 206 # See http://en.wikipedia.org/wiki/Portable_Network_Graphics#Color_depth
198 # for details about the color type code. 207 # for details about the color type code.
199 function get_color_type { 208 function get_color_type {
200 local file=$1 209 local file=$1
201 echo $(file $file | awk -F, '{print $3}' | awk '{print $2}') 210 echo $(file $file | awk -F, '{print $3}' | awk '{print $2}')
202 } 211 }
203 212
204 # Usage: optimize_size <file> 213 # Usage: optimize_size <file>
205 # Performs png file optimization. 214 # Performs png file optimization.
206 function optimize_size { 215 function optimize_size {
207 tput el 216 tput el
208 local file=$1 217 local file=$1
209 echo -n "$file " 218 info -n "$file "
210 219
211 advdef -q -z -4 $file 220 advdef -q -z -4 $file
212 221
213 pngout -q -s4 -c0 -force $file $file.tmp.png 222 pngout -q -s4 -c0 -force $file $file.tmp.png
214 if [ -f $file.tmp.png ]; then 223 if [ -f $file.tmp.png ]; then
215 rm $file.tmp.png 224 rm $file.tmp.png
216 process_grayscale $file 225 process_grayscale $file
217 process_grayscale_alpha $file 226 process_grayscale_alpha $file
218 else 227 else
219 pngout -q -s4 -c4 -force $file $file.tmp.png 228 pngout -q -s4 -c4 -force $file $file.tmp.png
220 if [ -f $file.tmp.png ]; then 229 if [ -f $file.tmp.png ]; then
221 rm $file.tmp.png 230 rm $file.tmp.png
222 process_grayscale_alpha $file 231 process_grayscale_alpha $file
223 else 232 else
224 process_rgb $file 233 process_rgb $file
225 fi 234 fi
226 fi 235 fi
227 236
228 echo -n "|filter" 237 info -n "|filter"
229 local old_color_type=$(get_color_type $file) 238 local old_color_type=$(get_color_type $file)
230 optipng -q -zc9 -zm8 -zs0-3 -f0-5 $file -out $file.tmp.png 239 optipng -q -zc9 -zm8 -zs0-3 -f0-5 $file -out $file.tmp.png
231 local new_color_type=$(get_color_type $file.tmp.png) 240 local new_color_type=$(get_color_type $file.tmp.png)
232 # optipng may corrupt a png file when reducing the color type 241 # optipng may corrupt a png file when reducing the color type
233 # to grayscale/grayscale+alpha. Just skip such cases until 242 # to grayscale/grayscale+alpha. Just skip such cases until
234 # the bug is fixed. See crbug.com/174505, crbug.com/174084. 243 # the bug is fixed. See crbug.com/174505, crbug.com/174084.
235 # The issue is reported in 244 # The issue is reported in
236 # https://sourceforge.net/tracker/?func=detail&aid=3603630&group_id=151404&ati d=780913 245 # https://sourceforge.net/tracker/?func=detail&aid=3603630&group_id=151404&ati d=780913
237 if [[ $old_color_type == "RGBA" && $new_color_type =~ gray.* ]] ; then 246 if [[ $old_color_type == "RGBA" && $new_color_type =~ gray.* ]] ; then
238 rm $file.tmp.png 247 rm $file.tmp.png
239 echo -n "[skip opting]" 248 info -n "[skip opting]"
240 else 249 else
241 mv $file.tmp.png $file 250 mv $file.tmp.png $file
242 fi 251 fi
243 pngout -q -k1 -s1 $file 252 pngout -q -k1 -s1 $file
244 253
245 huffman_blocks $file 254 huffman_blocks $file
246 255
247 # TODO(oshima): Experiment with strategy 1. 256 # TODO(oshima): Experiment with strategy 1.
248 echo -n "|strategy" 257 info -n "|strategy"
249 if [ $OPTIMIZE_LEVEL == 2 ]; then 258 if [ $OPTIMIZE_LEVEL == 2 ]; then
250 for i in 3 2 0; do 259 for i in 3 2 0; do
251 pngout -q -k1 -ks -s$i $file 260 pngout -q -k1 -ks -s$i $file
252 done 261 done
253 else 262 else
254 pngout -q -k1 -ks -s1 $file 263 pngout -q -k1 -ks -s1 $file
255 fi 264 fi
256 265
257 if [ $OPTIMIZE_LEVEL == 2 ]; then 266 if [ $OPTIMIZE_LEVEL == 2 ]; then
258 random_huffman_table_trial $file 267 random_huffman_table_trial $file
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 302
294 tput el 303 tput el
295 if [ $new -lt $old ]; then 304 if [ $new -lt $old ]; then
296 echo -ne "$file : $old => $new ($diff bytes : $percent %)\n" 305 echo -ne "$file : $old => $new ($diff bytes : $percent %)\n"
297 mv "$tmp_file" "$file" 306 mv "$tmp_file" "$file"
298 let TOTAL_OLD_BYTES+=$old 307 let TOTAL_OLD_BYTES+=$old
299 let TOTAL_NEW_BYTES+=$new 308 let TOTAL_NEW_BYTES+=$new
300 let PROCESSED_FILE+=1 309 let PROCESSED_FILE+=1
301 else 310 else
302 if [ $OPTIMIZE_LEVEL == 0 ]; then 311 if [ $OPTIMIZE_LEVEL == 0 ]; then
303 echo -ne "$file : skipped\r" 312 info -ne "$file : skipped\r"
304 fi 313 fi
305 rm $tmp_file 314 rm $tmp_file
306 fi 315 fi
307 } 316 }
308 317
309 function optimize_dir { 318 function optimize_dir {
310 local dir=$1 319 local dir=$1
311 if $using_cygwin ; then 320 if $using_cygwin ; then
312 dir=$(cygpath -w $dir) 321 dir=$(cygpath -w $dir)
313 fi 322 fi
(...skipping 26 matching lines...) Expand all
340 which $program > /dev/null 2>&1 349 which $program > /dev/null 2>&1
341 if [ $? != 0 ]; then 350 if [ $? != 0 ]; then
342 echo "Couldn't find $program. Please download and install it from $url ." 351 echo "Couldn't find $program. Please download and install it from $url ."
343 exit 1 352 exit 1
344 fi 353 fi
345 } 354 }
346 355
347 function show_help { 356 function show_help {
348 local program=$(basename $0) 357 local program=$(basename $0)
349 echo \ 358 echo \
350 "Usage: $program [options] dir ... 359 "Usage: $program [options] <dir> ...
351 360
352 $program is a utility to reduce the size of png files by removing 361 $program is a utility to reduce the size of png files by removing
353 unnecessary chunks and compressing the image. 362 unnecessary chunks and compressing the image.
354 363
355 Options: 364 Options:
356 -o<optimize_level> Specify optimization level: (default is 1) 365 -o<optimize_level> Specify optimization level: (default is 1)
357 0 Just run pngcrush. It removes unnecessary chunks and perform basic 366 0 Just run pngcrush. It removes unnecessary chunks and perform basic
358 optimization on the encoded data. 367 optimization on the encoded data.
359 1 Optimize png files using pngout/optipng and advdef. This can further 368 1 Optimize png files using pngout/optipng and advdef. This can further
360 reduce addtional 5~30%. This is the default level. 369 reduce addtional 5~30%. This is the default level.
361 2 Aggressively optimize the size of png files. This may produce 370 2 Aggressively optimize the size of png files. This may produce
362 addtional 1%~5% reduction. Warning: this is *VERY* 371 addtional 1%~5% reduction. Warning: this is *VERY*
363 slow and can take hours to process all files. 372 slow and can take hours to process all files.
364 -r<revision> If this is specified, the script processes only png files 373 -r<revision> If this is specified, the script processes only png files
365 changed since this revision. The <dir> options will be used 374 changed since this revision. The <dir> options will be used
366 to narrow down the files under specific directories. 375 to narrow down the files under specific directories.
376 -s Run as subprocess. This may be used to parallelize execution.
377 Usage: find <dir> -name \"*.png\" | xargs -n1 -P16 $program -s -o2
367 -h Print this help text." 378 -h Print this help text."
368 exit 1 379 exit 1
369 } 380 }
370 381
371 if [ ! -e ../.gclient ]; then 382 if [ ! -e ../.gclient ]; then
372 echo "$0 must be run in src directory" 383 echo "$0 must be run in src directory"
373 exit 1 384 exit 1
374 fi 385 fi
375 386
376 if [ "$(expr substr $(uname -s) 1 6)" == "CYGWIN" ]; then 387 if [ "$(expr substr $(uname -s) 1 6)" == "CYGWIN" ]; then
377 using_cygwin=true 388 using_cygwin=true
378 else 389 else
379 using_cygwin=false 390 using_cygwin=false
380 fi 391 fi
381 392
382 OPTIMIZE_LEVEL=1 393 OPTIMIZE_LEVEL=1
383 # Parse options 394 # Parse options
384 while getopts o:r:h opts 395 while getopts o:r:h:s opts
385 do 396 do
386 case $opts in 397 case $opts in
387 r) 398 r)
388 COMMIT=$(git svn find-rev r$OPTARG | tail -1) || exit 399 COMMIT=$(git svn find-rev r$OPTARG | tail -1) || exit
389 if [ -z "$COMMIT" ] ; then 400 if [ -z "$COMMIT" ] ; then
390 echo "Revision $OPTARG not found" 401 echo "Revision $OPTARG not found"
391 show_help 402 show_help
392 fi 403 fi
393 ;; 404 ;;
394 o) 405 o)
395 if [[ ! "$OPTARG" =~ [012] ]] ; then 406 if [[ ! "$OPTARG" =~ [012] ]] ; then
396 show_help 407 show_help
397 fi 408 fi
398 OPTIMIZE_LEVEL=$OPTARG 409 OPTIMIZE_LEVEL=$OPTARG
399 ;; 410 ;;
411 s)
412 let SUBPROCESS=1
413 ;;
400 [h?]) 414 [h?])
401 show_help;; 415 show_help;;
402 esac 416 esac
403 done 417 done
404 418
405 # Remove options from argument list. 419 # Remove options from argument list.
406 shift $(($OPTIND -1)) 420 shift $(($OPTIND -1))
407 421
408 # Make sure we have all necessary commands installed. 422 # Make sure we have all necessary commands installed.
409 install_if_not_installed pngcrush pngcrush 423 install_if_not_installed pngcrush pngcrush
(...skipping 20 matching lines...) Expand all
430 TMP_DIR=$(cygpath -w $TMP_DIR) 444 TMP_DIR=$(cygpath -w $TMP_DIR)
431 fi 445 fi
432 446
433 # Make sure we cleanup temp dir 447 # Make sure we cleanup temp dir
434 trap "rm -rf $TMP_DIR" EXIT 448 trap "rm -rf $TMP_DIR" EXIT
435 449
436 # If no directories are specified, optimize all directories. 450 # If no directories are specified, optimize all directories.
437 DIRS=$@ 451 DIRS=$@
438 set ${DIRS:=$ALL_DIRS} 452 set ${DIRS:=$ALL_DIRS}
439 453
440 echo "Optimize level=$OPTIMIZE_LEVEL" 454 info "Optimize level=$OPTIMIZE_LEVEL"
455
441 if [ -n "$COMMIT" ] ; then 456 if [ -n "$COMMIT" ] ; then
442 ALL_FILES=$(git diff --name-only $COMMIT HEAD $DIRS | grep "png$") 457 ALL_FILES=$(git diff --name-only $COMMIT HEAD $DIRS | grep "png$")
443 ALL_FILES_LIST=( $ALL_FILES ) 458 ALL_FILES_LIST=( $ALL_FILES )
444 echo "Processing ${#ALL_FILES_LIST[*]} files" 459 echo "Processing ${#ALL_FILES_LIST[*]} files"
445 for f in $ALL_FILES; do 460 for f in $ALL_FILES; do
446 if [ -f $f ] ; then 461 if [ -f $f ] ; then
447 optimize_file $f 462 optimize_file $f
448 else 463 else
449 echo "Skipping deleted file: $f"; 464 echo "Skipping deleted file: $f";
450 fi 465 fi
451 done 466 done
467 elif [ $SUBPROCESS -eq 1 ]; then
468 for f in $DIRS; do
469 optimize_file $f
470 done
452 else 471 else
453 for d in $DIRS; do 472 for d in $DIRS; do
454 echo "Optimizing png files in $d" 473 echo "Optimizing png files in $d"
455 optimize_dir $d 474 optimize_dir $d
456 echo 475 echo
457 done 476 done
458 fi 477 fi
459 478
460 # Print the results. 479 # Print the results.
480 if [ $SUBPROCESS -eq 1 ]; then
481 exit 0
482 fi
483
461 if [ $PROCESSED_FILE == 0 ]; then 484 if [ $PROCESSED_FILE == 0 ]; then
462 echo "Did not find any files (out of $TOTAL_FILE files)" \ 485 echo "Did not find any files (out of $TOTAL_FILE files)" \
463 "that could be optimized" \ 486 "that could be optimized" \
464 "in $(date -u -d @$SECONDS +%T)s" 487 "in $(date -u -d @$SECONDS +%T)s"
465 else 488 else
466 let diff=$TOTAL_OLD_BYTES-$TOTAL_NEW_BYTES 489 let diff=$TOTAL_OLD_BYTES-$TOTAL_NEW_BYTES
467 let percent=$diff*100/$TOTAL_OLD_BYTES 490 let percent=$diff*100/$TOTAL_OLD_BYTES
468 echo "Processed $PROCESSED_FILE files (out of $TOTAL_FILE files)" \ 491 echo "Processed $PROCESSED_FILE files (out of $TOTAL_FILE files)" \
469 "in $(date -u -d @$SECONDS +%T)s" 492 "in $(date -u -d @$SECONDS +%T)s"
470 echo "Result : $TOTAL_OLD_BYTES => $TOTAL_NEW_BYTES bytes" \ 493 echo "Result : $TOTAL_OLD_BYTES => $TOTAL_NEW_BYTES bytes" \
471 "($diff bytes : $percent %)" 494 "($diff bytes : $percent %)"
472 fi 495 fi
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698