do not resize image if not necessary
This commit is contained in:
51
config.php
Normal file → Executable file
51
config.php
Normal file → Executable 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,33 +4394,34 @@ class ToolBox
|
||||
$iResizedHeight = $iMaxHeight;
|
||||
$iResizedWidth = ($iResizedHeight / $iHeight) * $iWidth;
|
||||
}
|
||||
|
||||
//create image from source
|
||||
$oSource = call_user_func('imagecreatefrom'.$sImageExt, $sInPath);
|
||||
|
||||
//Resize
|
||||
$oThumb = imagecreatetruecolor($iResizedWidth, $iResizedHeight);
|
||||
imagecopyresized($oThumb, $oSource, 0, 0, 0, 0, $iResizedWidth, $iResizedHeight, $iWidth, $iHeight);
|
||||
|
||||
//Save
|
||||
if(file_exists($sOutPath)) unlink($sOutPath);
|
||||
if(!call_user_func_array('image'.$sImageExt, array($oThumb, $sOutPath)))
|
||||
{
|
||||
$asResult['error'] = 'Unable to create thumbnail : '.$sOutPath;
|
||||
}
|
||||
}
|
||||
else
|
||||
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;
|
||||
|
||||
//create image from source
|
||||
$oSource = call_user_func('imagecreatefrom'.$sImageExt, $sInPath);
|
||||
|
||||
//Resize
|
||||
$oThumb = imagecreatetruecolor($iResizedWidth, $iResizedHeight);
|
||||
imagecopyresized($oThumb, $oSource, 0, 0, 0, 0, $iResizedWidth, $iResizedHeight, $iWidth, $iHeight);
|
||||
|
||||
//Save
|
||||
if(file_exists($sOutPath)) unlink($sOutPath);
|
||||
if(!call_user_func_array('image'.$sImageExt, array($oThumb, $sOutPath)))
|
||||
{
|
||||
$asResult['error'] = 'Unable to create thumbnail : '.$sOutPath;
|
||||
}
|
||||
$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);
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user