createThumbnail: constraint on only 1 parameter
This commit is contained in:
@@ -173,7 +173,7 @@ class ToolBox
|
|||||||
return $iCount > 1;
|
return $iCount > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createThumbnail($sInPath, $iMaxWidth, $iMaxHeight, $sOutPath='', $bDeleteIn=false, $asImageExts=array('jpg', 'jpeg', 'gif', 'png'), $bCrop=false)
|
public static function createThumbnail($sInPath, $iMaxWidth, $iMaxHeight=0, $sOutPath='', $bDeleteIn=false, $asImageExts=array('jpg', 'jpeg', 'gif', 'png'), $bCrop=false)
|
||||||
{
|
{
|
||||||
$asResult = array('error'=>'');
|
$asResult = array('error'=>'');
|
||||||
|
|
||||||
@@ -190,9 +190,15 @@ class ToolBox
|
|||||||
|
|
||||||
//New sizes
|
//New sizes
|
||||||
if(!in_array($sImageExt, $asImageExts) && !empty($asImageExts)) $asResult['error'] = 'Wrong file type: '.$sImageExt;
|
if(!in_array($sImageExt, $asImageExts) && !empty($asImageExts)) $asResult['error'] = 'Wrong file type: '.$sImageExt;
|
||||||
|
elseif($iMaxWidth==0 && $iMaxHeight==0) $asResult['error'] = 'At least one dimension must be resized (width and/or height)';
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
list($iWidth, $iHeight) = getimagesize($sInPath);
|
list($iWidth, $iHeight) = getimagesize($sInPath);
|
||||||
|
|
||||||
|
//Limit on only 1 parameter
|
||||||
|
if($iMaxWidth==0) $iMaxWidth = $iWidth * $iMaxHeight / $iHeight;
|
||||||
|
elseif($iMaxHeight==0) $iMaxHeight = $iHeight * $iMaxWidth / $iWidth;
|
||||||
|
|
||||||
if($iWidth > $iMaxWidth || $iHeight > $iMaxHeight)
|
if($iWidth > $iMaxWidth || $iHeight > $iMaxHeight)
|
||||||
{
|
{
|
||||||
$dResizeDeltaWidth = $iWidth - $iMaxWidth;
|
$dResizeDeltaWidth = $iWidth - $iMaxWidth;
|
||||||
@@ -236,10 +242,10 @@ class ToolBox
|
|||||||
if($sImageExt=='gif' && self::isAnimatedGif($sInPath))
|
if($sImageExt=='gif' && self::isAnimatedGif($sInPath))
|
||||||
{
|
{
|
||||||
$sContent = file_get_contents($sInPath);
|
$sContent = file_get_contents($sInPath);
|
||||||
$sBigGifPath = Databap::DOC_TMP_FOLDER.uniqid();
|
$sBigGifPath = uniqid().$sOutPath.'.big';
|
||||||
$sCoalescePath = Databap::DOC_TMP_FOLDER.uniqid();
|
$sCoalescePath = uniqid().$sOutPath.'.coalesce';
|
||||||
|
|
||||||
file_put_contents($sBigGifPath, $sContent);
|
if(file_put_contents($sBigGifPath, $sContent)===false) $asResult['error'] = 'Unable to create temporary thumbnail : '.$sBigGifPath;
|
||||||
system('convert '.$sBigGifPath.' -coalesce '.$sCoalescePath);
|
system('convert '.$sBigGifPath.' -coalesce '.$sCoalescePath);
|
||||||
system('convert -size '.$iWidth.'x'.$iHeight.' '.$sCoalescePath.' -resize '.$iResizedWidth.'x'.$iResizedHeight.' '.$sOutPath);
|
system('convert -size '.$iWidth.'x'.$iHeight.' '.$sCoalescePath.' -resize '.$iResizedWidth.'x'.$iResizedHeight.' '.$sOutPath);
|
||||||
unlink($sBigGifPath);
|
unlink($sBigGifPath);
|
||||||
|
|||||||
Reference in New Issue
Block a user