cookutils diff modules/compressor @ rev 1064
modules/compressor: compress (optimize) GIF images using gifsicle
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Wed Jun 06 00:00:22 2018 +0300 (2018-06-06) |
parents | 2ad4e06e9141 |
children | c69daec36de2 |
line diff
1.1 --- a/modules/compressor Wed Apr 04 11:44:07 2018 +0300 1.2 +++ b/modules/compressor Wed Jun 06 00:00:22 2018 +0300 1.3 @@ -106,6 +106,7 @@ 1.4 man) find $install/usr/share/man -type f -exec ls -l \{\} \; ;; 1.5 png) find $install -type f -name '*.png' -exec ls -l \{\} \; ;; 1.6 svg) find $install -type f -name '*.svg' -exec ls -l \{\} \; ;; 1.7 + gif) find $install -type f -name '*.gif' -exec ls -l \{\} \; ;; 1.8 xml) find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; ;; 1.9 des) find $install -type f -name '*.desktop' -exec ls -l \{\} \; ;; 1.10 mo1) find $install -type f -name '*.mo' -exec ls -l \{\} \; ;; 1.11 @@ -383,6 +384,38 @@ 1.12 } 1.13 1.14 1.15 +# Function used after compile_rules() to compress all gif images 1.16 +# Compressing can be disabled with COOKOPTS="!gifz" 1.17 + 1.18 +compress_gif() { 1.19 + time0=$(get_time) 1.20 + [ "${COOKOPTS/!gifz/}" != "$COOKOPTS" ] && return 1.21 + size0=$(sizes gif); [ -z "$size0" ] && return 1.22 + 1.23 + tpi gifsicle 1.24 + 1.25 + action 'Compressing gif images...' 1.26 + 1.27 + if which gifsicle >/dev/null; then 1.28 + the_log="$(mktemp)" 1.29 + j="$(mktemp)" 1.30 + for i in $(IFS=$'\n' find $install -type f -name '*.gif'); do 1.31 + unset IFS 1.32 + # use intermediate file, if all well ($?=0), then substitute the original 1.33 + if gifsicle -O3 "$i" -o "$j" >> "$the_log" 2>&1; then 1.34 + mv "$j" "$i" 1.35 + else 1.36 + rm "$j" 1.37 + fi 1.38 + done 1.39 + else 1.40 + echo 'Warning: gifsicle not found.' > "$the_log" 1.41 + fi 1.42 + 1.43 + comp_summary "$time0" "$size0" "$(sizes gif)" "$the_log" 1.44 +} 1.45 + 1.46 + 1.47 # Function used after compile_rules() to shrink all *.ui and *.glade files: 1.48 # remove insignificant spaces and comments 1.49 # Compressing can be disabled with COOKOPTS="!uiz" 1.50 @@ -795,6 +828,7 @@ 1.51 compress_manpages 1.52 compress_png 1.53 compress_svg 1.54 + compress_gif 1.55 compress_ui 1.56 ;; 1.57 esac