diff --git a/inc/toolbox.php b/inc/toolbox.php index 2834170..ca46907 100755 --- a/inc/toolbox.php +++ b/inc/toolbox.php @@ -173,7 +173,7 @@ class ToolBox 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'=>''); @@ -190,9 +190,15 @@ class ToolBox //New sizes 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 { 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) { $dResizeDeltaWidth = $iWidth - $iMaxWidth; @@ -236,10 +242,10 @@ class ToolBox if($sImageExt=='gif' && self::isAnimatedGif($sInPath)) { $sContent = file_get_contents($sInPath); - $sBigGifPath = Databap::DOC_TMP_FOLDER.uniqid(); - $sCoalescePath = Databap::DOC_TMP_FOLDER.uniqid(); + $sBigGifPath = uniqid().$sOutPath.'.big'; + $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 -size '.$iWidth.'x'.$iHeight.' '.$sCoalescePath.' -resize '.$iResizedWidth.'x'.$iResizedHeight.' '.$sOutPath); unlink($sBigGifPath); @@ -273,7 +279,7 @@ class ToolBox $asResult['out'] = $sOutPath; } - if($bDeleteIn && $asResult['error']=='' && $sInPath != $sOutPath) unlink($sInPath); + if($bDeleteIn && $asResult['error'] == '' && $sInPath != $sOutPath) unlink($sInPath); return $asResult; }