Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge remote-tracking branch 'mainline/master'

Conflicts:
	image_optim.sh
  • Loading branch information...
commit 45ac1174870d27e1899171000d6dc05c2dbfe1da 2 parents d00f7e3 + a02791e
stefanbeller stefanbeller authored

Showing 1 changed file with 27 additions and 18 deletions. Show diff stats Hide diff stats

  1. +27 18 image_optim.sh
45 image_optim.sh
... ... @@ -1,4 +1,13 @@
1 1 #!/bin/bash
  2 +#TODO: also use pngout ?
  3 +
  4 +echo "To kill the script, run"
  5 +echo "while true ;do ; killall optipng ; killall advpng ; killall pngcrush ; done"
  6 +echo "for a while"
  7 +
  8 +
  9 +cpucores=`getconf _NPROCESSORS_ONLN`
  10 +
2 11
3 12 if [[ $(git rev-parse --is-inside-work-tree) != "true" ]] >& /dev/null ; then
4 13 echo "fatal: Not a git repository!"
@@ -36,6 +45,7 @@ timeend()
36 45 TD=`calc $TE - $TS`
37 46 }
38 47
  48 +
39 49 print()
40 50 {
41 51 ${VERBOSE} && echo $1
@@ -45,7 +55,7 @@ jpeg_remove_comment_and_exiv()
45 55 {
46 56 print "Removing comments and exiv data from jpegs."
47 57 timestart
48   - git ls-files ./ | grep -e "\.jpg$" -e "\.jpeg" | xargs -P ${MAX_CORES} -n 1 jpegoptim --strip-all >> /tmp/mytrimage_jpeg.log
  58 + git ls-files ./ | grep -e "\.jpg$" -e "\.jpeg" | xargs -P ${cpucores} -n 1 jpegoptim --strip-all >> /tmp/image_optim_jpeg.log
49 59 timeend
50 60 print "$TD"
51 61 }
@@ -54,9 +64,9 @@ png_optimize_all()
54 64 {
55 65 timestart
56 66 print "starting to optimize pngs"
57   - git ls-files ./ | grep "\.png$" | xargs -P ${MAX_CORES} -n 1 optipng -zc1-9 -zm1-9 -zs0-3 -f0-5 >> /tmp/mytrimage_png.log
58   - git ls-files ./ | grep "\.png$" | xargs -P ${MAX_CORES} -n 1 advpng -z4 >> /tmp/mytrimage_png.log
59   - git ls-files ./ | grep "\.png$" | xargs -P ${MAX_CORES} -n 1 -I '{}' pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time {} {}.foo >> /tmp/mytrimage_png.log
  67 + git ls-files ./ | grep "\.png$" | xargs -P ${cpucores} -n 1 optipng -zc1-9 -zm1-9 -zs0-3 -f0-5 >> /tmp/mytrimage_png.log
  68 + git ls-files ./ | grep "\.png$" | xargs -P ${cpucores} -n 1 advpng -z4 >> /tmp/mytrimage_png.log
  69 + git ls-files ./ | grep "\.png$" | xargs -P ${cpucores} -n 1 -I '{}' pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time {} {}.foo >> /tmp/mytrimage_png.log
60 70
61 71 for i in $(git ls-files ./ | grep "\.png$") ; do
62 72 if [[ `du -b $i | awk '{print $1}'` -gt `du -b $i.foo | awk '{print $1}'` ]] ; then
@@ -74,31 +84,30 @@ MAX_CORES=8
74 84 timestartglobal
75 85 jpeg_remove_comment_and_exiv
76 86 png_optimize_all
77   -
78 87 wait
79 88
80 89
81   -git status | grep "modified" | awk '{print $3}' > /tmp/mytrimage.todo #reprocess already changed images
82   -todonr=`cat /tmp/mytrimage.todo | wc -l`
  90 +git status | grep "modified" | awk '{print $3}' > /tmp/image_optim.todo #reprocess already changed images
  91 +todonr=`cat /tmp/image_optim.todo | wc -l`
83 92 echo $todonr todo
84 93 date=`date`
85   -git commit -a -m "mytrimage $date"
  94 +git commit -a -m "image_optim $date"
86 95
87 96 while [ $todonr -gt 0 ] ; do
88   - for i in $(cat /tmp/mytrimage.todo | grep -e "\.jpg$" -e "\.jpeg") ; do
89   - timestart
90   - jpegoptim -f --strip-all $i >> /tmp/mytrimage_jpeg.log
  97 + for i in $(cat /tmp/image_optim.todo | grep -e "\.jpg$" -e "\.jpeg") ; do
  98 + timestart
  99 + jpegoptim -f --strip-all $i >> /tmp/image_optim_jpeg.log
91 100 timeend
92 101 echo $TD $i
93 102 done &
94 103
95 104
96 105
97   - for i in $(cat /tmp/mytrimage.todo | grep "\.png$"); do #png
  106 + for i in $(cat /tmp/image_optim.todo | grep "\.png$"); do #png
98 107 timestart
99   - optipng -zc1-9 -zm1-9 -zs0-3 -f0-5 $i >> /tmp/mytrimage_png.log
100   - advpng -z4 $i >> /tmp/mytrimage_png.log
101   - pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time $i $i.foo >> /tmp/mytrimage_png.log
  108 + optipng -zc1-9 -zm1-9 -zs0-3 -f0-5 $i >> /tmp/image_optim_png.log
  109 + advpng -z4 $i >> /tmp/image_optim_png.log
  110 + pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time $i $i.foo >> /tmp/image_optim_png.log
102 111 #find out if we actually save some bytes or not
103 112 if [[ `du -b $i | awk '{print $1}'` -gt `du -b $i.foo | awk '{print $1}'` ]] ; then
104 113 mv $i.foo $i
@@ -110,11 +119,11 @@ while [ $todonr -gt 0 ] ; do
110 119 done &
111 120 wait
112 121
113   -git status | grep "modified" | awk '{print $3}' > /tmp/mytrimage.todo
114   -todonr=`cat /tmp/mytrimage.todo | wc -l`
  122 +git status | grep "modified" | awk '{print $3}' > /tmp/image_optim.todo
  123 +todonr=`cat /tmp/image_optim.todo | wc -l`
115 124 echo $todonr todo
116 125 date=`date`
117   -git commit -a -m "mytrimage $date"
  126 +git commit -a -m "image_optim $date"
118 127 done
119 128
120 129 timeendglobal

0 comments on commit 45ac117

Please sign in to comment.
Something went wrong with that request. Please try again.