[add] #463 : Add hash in image name
This commit is contained in:
parent
a12c61efea
commit
1dbf462108
2 changed files with 32 additions and 34 deletions
|
@ -4,19 +4,19 @@
|
||||||
# All info at http://forge.leslibres.org/projects/soshot
|
# All info at http://forge.leslibres.org/projects/soshot
|
||||||
|
|
||||||
site=$1 # url for thumbshot
|
site=$1 # url for thumbshot
|
||||||
md5Site=$2 # md5(url) is the name of final image
|
hashUrl=$2 # hash(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=3 # max parralle work for me the best is nb 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=false # log all generation success and error
|
||||||
randomSleep=`echo $((RANDOM%20))`
|
randomSleep=`echo $((RANDOM%20))`
|
||||||
optimizeTool='' # external tool form optimize png
|
optimizeTool='' # external tool form optimize png
|
||||||
maxQueue=50 # max process in queue
|
maxQueue=50 # max process in queue
|
||||||
currentProcess=$(ps -e | grep -v grep | grep thumb_ | wc -l)
|
currentProcess=$(ps -e | grep -v grep | grep thumb_ | wc -l)
|
||||||
firstLevel=${md5Site:0:2}
|
firstLevel=${hashUrl:0:2}
|
||||||
secondLevel=${md5Site:2:2}
|
secondLevel=${hashUrl:2:2}
|
||||||
startPath=$firstLevel/$secondLevel/
|
startPath=$firstLevel/$secondLevel/
|
||||||
mkdir -p "cache/img/$startPath"
|
mkdir -p "cache/img/$startPath"
|
||||||
|
|
||||||
|
@ -40,15 +40,15 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
start_time=`date +%s`
|
start_time=`date +%s`
|
||||||
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/$hashUrl.png"
|
||||||
if [ ! -f "cache/tmp/$md5Site.png" ]
|
if [ ! -f "cache/tmp/$hashUrl.png" ]
|
||||||
then
|
then
|
||||||
echo 0
|
echo 0
|
||||||
errorCode=`echo $(curl -k --write-out %{http_code} --silent -S --connect-timeout $timeOut \--no-keepalive --output /dev/null $site)`
|
errorCode=`echo $(curl -k --write-out %{http_code} --silent -S --connect-timeout $timeOut \--no-keepalive --output /dev/null $site)`
|
||||||
case $errorCode in
|
case $errorCode in
|
||||||
000) cp "bin/000.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/000.png" "cache/img/$startPath""$md5Site.png" ;;
|
000) cp "bin/000.png" "cache/img/$startPath""$hashUrl""_thumb.png" && cp "bin/000.png" "cache/img/$startPath""$hashUrl.png" ;;
|
||||||
404) cp "bin/404.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/404.png" "cache/img/$startPath""$md5Site.png" ;;
|
404) cp "bin/404.png" "cache/img/$startPath""$hashUrl""_thumb.png" && cp "bin/404.png" "cache/img/$startPath""$hashUrl.png" ;;
|
||||||
*) cp "bin/error.png" "cache/img/$startPath""$md5Site""_thumb.png" && cp "bin/error.png" "cache/img/$startPath""$md5Site.png" ;;
|
*) cp "bin/error.png" "cache/img/$startPath""$hashUrl""_thumb.png" && cp "bin/error.png" "cache/img/$startPath""$hashUrl.png" ;;
|
||||||
esac
|
esac
|
||||||
if $log
|
if $log
|
||||||
then
|
then
|
||||||
|
@ -60,31 +60,31 @@ then
|
||||||
fi
|
fi
|
||||||
if [ $onlyThumb == 1 ]
|
if [ $onlyThumb == 1 ]
|
||||||
then
|
then
|
||||||
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$md5Site""_thumb.png"
|
convert "cache/tmp/$hashUrl.png" -crop 1280x1024+0+0 -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$hashUrl""_thumb.png"
|
||||||
if [ $optimizeTool ]
|
if [ $optimizeTool ]
|
||||||
then
|
then
|
||||||
eval $optimizeTool "cache/img/$startPath""$md5Site""_thumb.png"
|
eval $optimizeTool "cache/img/$startPath""$hashUrl""_thumb.png"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
convert "cache/tmp/$md5Site.png" -crop 1280x1024+0+0 "cache/img/$startPath""$md5Site.png"
|
convert "cache/tmp/$hashUrl.png" -crop 1280x1024+0+0 "cache/img/$startPath""$hashUrl.png"
|
||||||
convert "cache/img/$startPath""$md5Site.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$md5Site""_thumb.png"
|
convert "cache/img/$startPath""$hashUrl.png" -filter Lanczos -thumbnail "$thumbSize" "cache/img/$startPath""$hashUrl""_thumb.png"
|
||||||
if [ $optimizeTool ]
|
if [ $optimizeTool ]
|
||||||
then
|
then
|
||||||
eval $optimizeTool "cache/img/$startPath""$md5Site""_thumb.png" "cache/img/$startPath""$md5Site.png"
|
eval $optimizeTool "cache/img/$startPath""$hashUrl""_thumb.png" "cache/img/$startPath""$hashUrl.png"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
rm "cache/tmp/$md5Site.png"
|
rm "cache/tmp/$hashUrl.png"
|
||||||
|
|
||||||
if [ $onlyThumb ]
|
if [ $onlyThumb ]
|
||||||
then
|
then
|
||||||
if [[ -f "cache/img/$startPath""$md5Site""_thumb.png" ]]
|
if [[ -f "cache/img/$startPath""$hashUrl""_thumb.png" ]]
|
||||||
then
|
then
|
||||||
echo 1
|
echo 1
|
||||||
else
|
else
|
||||||
echo 0
|
echo 0
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ -f "cache/img/$startPath""$md5Site""_thumb.png" && -f "cache/img/$startPath""$md5Site.png" ]]
|
if [[ -f "cache/img/$startPath""$hashUrl""_thumb.png" && -f "cache/img/$startPath""$hashUrl.png" ]]
|
||||||
then
|
then
|
||||||
echo 1
|
echo 1
|
||||||
else
|
else
|
||||||
|
|
32
index.php
32
index.php
|
@ -75,14 +75,14 @@ function testExistImg($file) {
|
||||||
* @author Knah Tsaeb
|
* @author Knah Tsaeb
|
||||||
* @date 2013-02-12
|
* @date 2013-02-12
|
||||||
* @param $url (string) url for thumbshot
|
* @param $url (string) url for thumbshot
|
||||||
* @param $md5Url (md5) md5($url)
|
* @param $hashUrl (md5) md5($url)
|
||||||
* @param $width (string) size of thumbnail 190x90
|
* @param $width (string) size of thumbnail 190x90
|
||||||
* @param $onlyThumb (bool)
|
* @param $onlyThumb (bool)
|
||||||
* @param $waiForResult (bool)
|
* @param $waiForResult (bool)
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
function launchScript($url, $md5Url, $width, $onlyThumb, $waitForResult = false) {
|
function launchScript($url, $hashUrl, $width, $onlyThumb, $waitForResult = false) {
|
||||||
$md5Url = escapeshellarg($md5Url);
|
$hashUrl = escapeshellarg($hashUrl);
|
||||||
$url = escapeshellarg($url);
|
$url = escapeshellarg($url);
|
||||||
$width = escapeshellarg($width);
|
$width = escapeshellarg($width);
|
||||||
if ($GLOBALS['config']['onlyThumb'] === true) {
|
if ($GLOBALS['config']['onlyThumb'] === true) {
|
||||||
|
@ -92,9 +92,9 @@ function launchScript($url, $md5Url, $width, $onlyThumb, $waitForResult = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($waitForResult === false) {
|
if ($waitForResult === false) {
|
||||||
exec('bin/thumb_server.sh ' . $url . ' ' . $md5Url . ' ' . $width . ' ' . $onlyThumb . ' > /dev/null &', $result);
|
exec('bin/thumb_server.sh ' . $url . ' ' . $hashUrl . ' ' . $width . ' ' . $onlyThumb . ' > /dev/null &', $result);
|
||||||
} else {
|
} else {
|
||||||
exec('bin/thumb_server.sh ' . $url . ' ' . $md5Url . ' ' . $width . ' ' . $onlyThumb . ' 1', $result);
|
exec('bin/thumb_server.sh ' . $url . ' ' . $hashUrl . ' ' . $width . ' ' . $onlyThumb . ' 1', $result);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -239,17 +239,15 @@ if ($_GET) {
|
||||||
$width = $GLOBALS['config']['defaultThumbSize'];
|
$width = $GLOBALS['config']['defaultThumbSize'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$md5Url = md5($defUrl);
|
$hashUrl = sha1($GLOBALS['config']['serverKey'] . $defUrl);
|
||||||
$startPath = substr($md5Url, 0,2).'/'.substr($md5Url, 2,2).'/';
|
$startPath = substr($hashUrl, 0, 2) . '/' . substr($hashUrl, 2, 2) . '/';
|
||||||
$file = 'cache/img/'.$startPath.$md5Url;
|
$file = 'cache/img/' . $startPath . $hashUrl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
|
if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
|
||||||
if (isset($ui['iw']) && (int)$ui['iw'] === 1) {
|
if (isset($ui['iw']) && (int)$ui['iw'] === 1) {
|
||||||
launchScript($defUrl, $md5Url, $width, $GLOBALS['config']['onlyThumb'], true);
|
launchScript($defUrl, $hashUrl, $width, $GLOBALS['config']['onlyThumb'], true);
|
||||||
} else {
|
} else {
|
||||||
$res = launchScript($defUrl, $md5Url, $width, $GLOBALS['config']['onlyThumb'], false);
|
$res = launchScript($defUrl, $hashUrl, $width, $GLOBALS['config']['onlyThumb'], false);
|
||||||
header("Content-type: image/png");
|
header("Content-type: image/png");
|
||||||
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
|
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
|
||||||
echo file_get_contents('bin/loadingGen.png');
|
echo file_get_contents('bin/loadingGen.png');
|
||||||
|
@ -290,12 +288,12 @@ if ($_POST) {
|
||||||
$width = $GLOBALS['config']['defaultThumbSize'];
|
$width = $GLOBALS['config']['defaultThumbSize'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$md5Url = md5($defUrl);
|
$hashUrl = sha1($GLOBALS['config']['serverKey'] . $defUrl);
|
||||||
$startPath = substr($md5Url, 0,2).'/'.substr($md5Url, 2,2).'/';
|
$startPath = substr($hashUrl, 0, 2) . '/' . substr($hashUrl, 2, 2) . '/';
|
||||||
$file = 'cache/img/'.$startPath . $md5Url;
|
$file = 'cache/img/' . $startPath . $hashUrl;
|
||||||
|
|
||||||
if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
|
if (testExistImg($file) !== true || isset($ui['fr']) && (int)$ui['fr'] === 1) {
|
||||||
launchScript($defUrl, $md5Url, $width, $GLOBALS['config']['onlyThumb'], true);
|
launchScript($defUrl, $hashUrl, $width, $GLOBALS['config']['onlyThumb'], true);
|
||||||
}
|
}
|
||||||
$success = array('normal' => $file . '.png', 'thumb' => $file . '_thumb.png');
|
$success = array('normal' => $file . '.png', 'thumb' => $file . '_thumb.png');
|
||||||
}
|
}
|
||||||
|
@ -349,7 +347,7 @@ if (empty($width)) {
|
||||||
<?php
|
<?php
|
||||||
if (!empty($success)) {
|
if (!empty($success)) {
|
||||||
echo '<div id="result">';
|
echo '<div id="result">';
|
||||||
echo '<img src="', $success['thumb'], '?r=', time(), '"/>';
|
echo '<img src="', $success['thumb'], '?r=', time(), '"/>';
|
||||||
echo '<p><label>', $width, '</label><input type="text" value="http://', $_SERVER['SERVER_NAME'], '/', $success['thumb'], '" onclick="this.select()"/></p>';
|
echo '<p><label>', $width, '</label><input type="text" value="http://', $_SERVER['SERVER_NAME'], '/', $success['thumb'], '" onclick="this.select()"/></p>';
|
||||||
if ($GLOBALS['config']['onlyThumb'] === false) {
|
if ($GLOBALS['config']['onlyThumb'] === false) {
|
||||||
echo '<p><label>1280x1024</label><input type="text" value="http://', $_SERVER['SERVER_NAME'], '/', $success['normal'], '" onclick="this.select()"/></p>';
|
echo '<p><label>1280x1024</label><input type="text" value="http://', $_SERVER['SERVER_NAME'], '/', $success['normal'], '" onclick="this.select()"/></p>';
|
||||||
|
|
Loading…
Reference in a new issue