Permalink
Browse files

Merge remote-tracking branch 'mainline/master'

Conflicts:
	image_optim.sh
  • Loading branch information...
2 parents d00f7e3 + a02791e commit 45ac1174870d27e1899171000d6dc05c2dbfe1da @stefanbeller stefanbeller committed Jan 16, 2013
Showing with 27 additions and 18 deletions.
  1. +27 −18 image_optim.sh
View
45 image_optim.sh
@@ -1,4 +1,13 @@
#!/bin/bash
+#TODO: also use pngout ?
+
+echo "To kill the script, run"
+echo "while true ;do ; killall optipng ; killall advpng ; killall pngcrush ; done"
+echo "for a while"
+
+
+cpucores=`getconf _NPROCESSORS_ONLN`
+
if [[ $(git rev-parse --is-inside-work-tree) != "true" ]] >& /dev/null ; then
echo "fatal: Not a git repository!"
@@ -36,6 +45,7 @@ timeend()
TD=`calc $TE - $TS`
}
+
print()
{
${VERBOSE} && echo $1
@@ -45,7 +55,7 @@ jpeg_remove_comment_and_exiv()
{
print "Removing comments and exiv data from jpegs."
timestart
- git ls-files ./ | grep -e "\.jpg$" -e "\.jpeg" | xargs -P ${MAX_CORES} -n 1 jpegoptim --strip-all >> /tmp/mytrimage_jpeg.log
+ git ls-files ./ | grep -e "\.jpg$" -e "\.jpeg" | xargs -P ${cpucores} -n 1 jpegoptim --strip-all >> /tmp/image_optim_jpeg.log
timeend
print "$TD"
}
@@ -54,9 +64,9 @@ png_optimize_all()
{
timestart
print "starting to optimize pngs"
- git ls-files ./ | grep "\.png$" | xargs -P ${MAX_CORES} -n 1 optipng -zc1-9 -zm1-9 -zs0-3 -f0-5 >> /tmp/mytrimage_png.log
- git ls-files ./ | grep "\.png$" | xargs -P ${MAX_CORES} -n 1 advpng -z4 >> /tmp/mytrimage_png.log
- 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
+ git ls-files ./ | grep "\.png$" | xargs -P ${cpucores} -n 1 optipng -zc1-9 -zm1-9 -zs0-3 -f0-5 >> /tmp/mytrimage_png.log
+ git ls-files ./ | grep "\.png$" | xargs -P ${cpucores} -n 1 advpng -z4 >> /tmp/mytrimage_png.log
+ 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
for i in $(git ls-files ./ | grep "\.png$") ; do
if [[ `du -b $i | awk '{print $1}'` -gt `du -b $i.foo | awk '{print $1}'` ]] ; then
@@ -74,31 +84,30 @@ MAX_CORES=8
timestartglobal
jpeg_remove_comment_and_exiv
png_optimize_all
-
wait
-git status | grep "modified" | awk '{print $3}' > /tmp/mytrimage.todo #reprocess already changed images
-todonr=`cat /tmp/mytrimage.todo | wc -l`
+git status | grep "modified" | awk '{print $3}' > /tmp/image_optim.todo #reprocess already changed images
+todonr=`cat /tmp/image_optim.todo | wc -l`
echo $todonr todo
date=`date`
-git commit -a -m "mytrimage $date"
+git commit -a -m "image_optim $date"
while [ $todonr -gt 0 ] ; do
- for i in $(cat /tmp/mytrimage.todo | grep -e "\.jpg$" -e "\.jpeg") ; do
- timestart
- jpegoptim -f --strip-all $i >> /tmp/mytrimage_jpeg.log
+ for i in $(cat /tmp/image_optim.todo | grep -e "\.jpg$" -e "\.jpeg") ; do
+ timestart
+ jpegoptim -f --strip-all $i >> /tmp/image_optim_jpeg.log
timeend
echo $TD $i
done &
- for i in $(cat /tmp/mytrimage.todo | grep "\.png$"); do #png
+ for i in $(cat /tmp/image_optim.todo | grep "\.png$"); do #png
timestart
- optipng -zc1-9 -zm1-9 -zs0-3 -f0-5 $i >> /tmp/mytrimage_png.log
- advpng -z4 $i >> /tmp/mytrimage_png.log
- pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time $i $i.foo >> /tmp/mytrimage_png.log
+ optipng -zc1-9 -zm1-9 -zs0-3 -f0-5 $i >> /tmp/image_optim_png.log
+ advpng -z4 $i >> /tmp/image_optim_png.log
+ pngcrush -rem gAMA -rem alla -rem cHRM -rem iCCP -rem sRGB -rem time $i $i.foo >> /tmp/image_optim_png.log
#find out if we actually save some bytes or not
if [[ `du -b $i | awk '{print $1}'` -gt `du -b $i.foo | awk '{print $1}'` ]] ; then
mv $i.foo $i
@@ -110,11 +119,11 @@ while [ $todonr -gt 0 ] ; do
done &
wait
-git status | grep "modified" | awk '{print $3}' > /tmp/mytrimage.todo
-todonr=`cat /tmp/mytrimage.todo | wc -l`
+git status | grep "modified" | awk '{print $3}' > /tmp/image_optim.todo
+todonr=`cat /tmp/image_optim.todo | wc -l`
echo $todonr todo
date=`date`
-git commit -a -m "mytrimage $date"
+git commit -a -m "image_optim $date"
done
timeendglobal

0 comments on commit 45ac117

Please sign in to comment.