do not resize image if not necessary
This commit is contained in:
55
config.php
Normal file → Executable file
55
config.php
Normal file → Executable file
@@ -569,8 +569,19 @@ class Databap extends PhpObject
|
|||||||
|
|
||||||
//Image
|
//Image
|
||||||
$oImages = $oPost->getElementsByTagName('img');
|
$oImages = $oPost->getElementsByTagName('img');
|
||||||
foreach($oImages as $oImage) {if($oImage->getAttribute('class') == 'badge-item-img') break;}
|
foreach($oImages as $oImage)
|
||||||
$asResult = $this->downloadToTmp($oImage->getAttribute('src'));
|
{
|
||||||
|
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']=='')
|
if($asResult['error']=='')
|
||||||
{
|
{
|
||||||
@@ -4355,8 +4366,9 @@ class ToolBox
|
|||||||
public static function createThumbnail($sInPath, $iMaxWidth, $iMaxHeight, $sOutPath='', $bDeleteIn=false)
|
public static function createThumbnail($sInPath, $iMaxWidth, $iMaxHeight, $sOutPath='', $bDeleteIn=false)
|
||||||
{
|
{
|
||||||
$asResult = array('error'=>'');
|
$asResult = array('error'=>'');
|
||||||
|
|
||||||
//Look up the extension to choose the image creator
|
//Look up the extension to choose the image creator
|
||||||
|
//TODO use MIME types
|
||||||
$sInInfo = pathinfo($sInPath);
|
$sInInfo = pathinfo($sInPath);
|
||||||
$sInName = strtolower($sInInfo['basename']);
|
$sInName = strtolower($sInInfo['basename']);
|
||||||
$sImageExt = strtolower($sInInfo['extension']);
|
$sImageExt = strtolower($sInInfo['extension']);
|
||||||
@@ -4365,7 +4377,7 @@ class ToolBox
|
|||||||
//New Destination folder
|
//New Destination folder
|
||||||
if($sOutPath=='') $sOutPath = $sInPath;
|
if($sOutPath=='') $sOutPath = $sInPath;
|
||||||
elseif(substr($sOutPath, -1)=='/') $sOutPath .= $sInName;
|
elseif(substr($sOutPath, -1)=='/') $sOutPath .= $sInName;
|
||||||
|
|
||||||
//New sizes
|
//New sizes
|
||||||
if(in_array($sImageExt, Databap::$UPLOAD_IMG_EXTS))
|
if(in_array($sImageExt, Databap::$UPLOAD_IMG_EXTS))
|
||||||
{
|
{
|
||||||
@@ -4382,33 +4394,34 @@ class ToolBox
|
|||||||
$iResizedHeight = $iMaxHeight;
|
$iResizedHeight = $iMaxHeight;
|
||||||
$iResizedWidth = ($iResizedHeight / $iHeight) * $iWidth;
|
$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;
|
$iResizedWidth = $iWidth;
|
||||||
$iResizedHeight = $iHeight;
|
$iResizedHeight = $iHeight;
|
||||||
|
if(!copy($sInPath, $sOutPath)) $asResult['error'] = 'Copy failed from '.$sInPath.' to '.$sOutPath;
|
||||||
}
|
}
|
||||||
$asResult['width'] = $iResizedWidth;
|
$asResult['width'] = $iResizedWidth;
|
||||||
$asResult['height'] = $iResizedHeight;
|
$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;
|
$asResult['out'] = $sOutPath;
|
||||||
}
|
}
|
||||||
else $asResult['error'] = 'Wrong file type';
|
else $asResult['error'] = 'Wrong file type';
|
||||||
|
|
||||||
if($bDeleteIn && $asResult['error']=='') unlink($sInPath);
|
if($bDeleteIn && $asResult['error']=='' && $sInPath != $sOutPath) unlink($sInPath);
|
||||||
|
|
||||||
return $asResult;
|
return $asResult;
|
||||||
}
|
}
|
||||||
@@ -4447,7 +4460,7 @@ function pre($sText, $sMode='return', $bDie=false, $sTitle='Test')
|
|||||||
|
|
||||||
function dlog($sText, $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