[add] #461 : limit global queue
[add] #460 : external tools for optimize png
BIN
bin/000.png
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 1.2 KiB |
BIN
bin/404.png
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 1 KiB |
BIN
bin/error.png
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 1.9 KiB |
|
@ -1,17 +1,25 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# inspirated source http://www.cambus.net/blog/page/3/ for global idea
|
# inspirated source http://www.cambus.net/creating-thumbnails-using-phantomjs-and-imagemagick/ for global idea
|
||||||
# https://gist.github.com/rsvp/1171304 for httpstatus code
|
# https://gist.github.com/rsvp/1171304 for httpstatus code
|
||||||
# All info at http://forge.leslibres.org/projects/soshot
|
# All info at http://forge.leslibres.org/projects/soshot
|
||||||
|
|
||||||
site=$1 # url must be encode by url_encode() or equivalent ex : http://google.com
|
site=$1 # url for thumbshot
|
||||||
md5Site=$2 # md5(url) is the name of final image
|
md5Site=$2 # md5(url) is the name of final image
|
||||||
thumbSize=$3 # size of thumb widthxheight ex : 190x90
|
thumbSize=$3 # size of thumb widthxheight ex : 190x90
|
||||||
onlyThumb=$4 # make only thumbshot no full size image
|
onlyThumb=$4 # make only thumbshot no full size image
|
||||||
waitForResult=$5 # if true we try to make soon as possible or add to queue
|
waitForResult=$5 # if true we try to make soon as possible or add to queue
|
||||||
maxThread=2 # max parralle work for me the best is processor core - 1
|
maxThread=3 # max parralle work for me the best is nb core - 1
|
||||||
timeOut=60 # default time out after this time the site are declared in error
|
timeOut=60 # default time out after this time the site are declared in error
|
||||||
log=false # log all generation success and error
|
log=true # log all generation success and error
|
||||||
randomSleep=`echo $((RANDOM%20))`
|
randomSleep=`echo $((RANDOM%20))`
|
||||||
|
optimizeTool='' # external tool form optimize png
|
||||||
|
maxQueue=50 # max process in queue
|
||||||
|
currentProcess=$(ps -e | grep -v grep | grep thumb_ | wc -l)
|
||||||
|
|
||||||
|
if [ $currentProcess -gt $maxQueue ]
|
||||||
|
then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! $waitForResult ]
|
if [ ! $waitForResult ]
|
||||||
then
|
then
|
||||||
|
@ -21,10 +29,8 @@ then
|
||||||
sleep `echo $((RANDOM%20))`
|
sleep `echo $((RANDOM%20))`
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
start_time=`date +%s`
|
start_time=`date +%s`
|
||||||
#firstLevel=${md5Site:0:2}
|
|
||||||
#secondLevel=${md5Site:2:2}
|
|
||||||
#mkdir -p "bin/img/$firstLevel/$secondLevel/"
|
|
||||||
timeout $timeOut ./bin/phantomjs --disk-cache=false --local-storage-path=/bin/ --ignore-ssl-errors=true /bin/rasterize.js "$site" "cache/tmp/$md5Site.png"
|
timeout $timeOut ./bin/phantomjs --disk-cache=false --local-storage-path=/bin/ --ignore-ssl-errors=true /bin/rasterize.js "$site" "cache/tmp/$md5Site.png"
|
||||||
if [ ! -f "cache/tmp/$md5Site.png" ]
|
if [ ! -f "cache/tmp/$md5Site.png" ]
|
||||||
then
|
then
|
||||||
|
@ -46,9 +52,17 @@ fi
|
||||||
if [ $onlyThumb ]
|
if [ $onlyThumb ]
|
||||||
then
|
then
|
||||||
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "cache/img/$md5Site""_thumb.png"
|
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "cache/img/$md5Site""_thumb.png"
|
||||||
|
if [ $optimizeTool ]
|
||||||
|
then
|
||||||
|
eval $optimizeTool "cache/img/$md5Site""_thumb.png"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$md5Site.png" &&
|
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$md5Site.png" &&
|
||||||
convert "cache/img/$md5Site.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$md5Site""_thumb.png"
|
convert "cache/img/$md5Site.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$md5Site""_thumb.png"
|
||||||
|
if [ $optimizeTool ]
|
||||||
|
then
|
||||||
|
eval $optimizeTool "cache/img/$md5Site""_thumb.png" "cache/img/$md5Site.png"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
rm "cache/tmp/$md5Site.png"
|
rm "cache/tmp/$md5Site.png"
|
||||||
|
|
||||||
|
|