do not resize image if not necessary

This commit is contained in:
2013-08-26 22:03:32 +02:00
parent 2c90e20e1a
commit b1e47ea855

37
config.php Normal file → Executable file
View File

@@ -569,8 +569,19 @@ class Databap extends PhpObject
//Image
$oImages = $oPost->getElementsByTagName('img');
foreach($oImages as $oImage) {if($oImage->getAttribute('class') == 'badge-item-img') break;}
$asResult = $this->downloadToTmp($oImage->getAttribute('src'));
foreach($oImages as $oImage)
{
switch($oImage->getAttribute('class'))
{
case 'badge-item-animated-img':
$o9gagImage = $oImage;
break 2;
case 'badge-item-img':
$o9gagImage = $oImage;
break;
}
}
$asResult = $this->downloadToTmp($o9gagImage->getAttribute('src'));
if($asResult['error']=='')
{
@@ -4357,6 +4368,7 @@ class ToolBox
$asResult = array('error'=>'');
//Look up the extension to choose the image creator
//TODO use MIME types
$sInInfo = pathinfo($sInPath);
$sInName = strtolower($sInInfo['basename']);
$sImageExt = strtolower($sInInfo['extension']);
@@ -4382,14 +4394,6 @@ class ToolBox
$iResizedHeight = $iMaxHeight;
$iResizedWidth = ($iResizedHeight / $iHeight) * $iWidth;
}
}
else
{
$iResizedWidth = $iWidth;
$iResizedHeight = $iHeight;
}
$asResult['width'] = $iResizedWidth;
$asResult['height'] = $iResizedHeight;
//create image from source
$oSource = call_user_func('imagecreatefrom'.$sImageExt, $sInPath);
@@ -4404,11 +4408,20 @@ class ToolBox
{
$asResult['error'] = 'Unable to create thumbnail : '.$sOutPath;
}
}
elseif($sInPath != $sOutPath)
{
$iResizedWidth = $iWidth;
$iResizedHeight = $iHeight;
if(!copy($sInPath, $sOutPath)) $asResult['error'] = 'Copy failed from '.$sInPath.' to '.$sOutPath;
}
$asResult['width'] = $iResizedWidth;
$asResult['height'] = $iResizedHeight;
$asResult['out'] = $sOutPath;
}
else $asResult['error'] = 'Wrong file type';
if($bDeleteIn && $asResult['error']=='') unlink($sInPath);
if($bDeleteIn && $asResult['error']=='' && $sInPath != $sOutPath) unlink($sInPath);
return $asResult;
}
@@ -4447,7 +4460,7 @@ function pre($sText, $sMode='return', $bDie=false, $sTitle='Test')
function dlog($sText, $sTitle='Test')
{
pre($sText, date('d/m/Y H:m:i').' - '.$sTitle, false, 'log');
pre($sText, 'log', false, date('d/m/Y H:m:i').' - '.$sTitle, false);
}
?>