protected function imgResize($path, $width, $height, $keepProportions = false, $resizeByBiggerSide = true, $destformat = null)
{
if (($s = @getimagesize($path)) == false) {
return false;
}
$result = false;
list($size_w, $size_h) = array($width, $height);
if ($keepProportions == true) {
list($orig_w, $orig_h, $new_w, $new_h) = array($s[0], $s[1], $width, $height);
/* Calculating image scale width and height */
$xscale = $orig_w / $new_w;
$yscale = $orig_h / $new_h;
/* Resizing by biggest side */
if ($resizeByBiggerSide) {
if ($orig_w > $orig_h) {
$size_h = $orig_h * $width / $orig_w;
$size_w = $width;
} else {
$size_w = $orig_w * $height / $orig_h;
$size_h = $height;
}
} else {
if ($orig_w > $orig_h) {
$size_w = $orig_w * $height / $orig_h;
$size_h = $height;
} else {
$size_h = $orig_h * $width / $orig_w;
$size_w = $width;
}
}
}
switch ($this->imgLib) {
case 'imagick':
try {
$img = new imagick($path);
} catch (Exception $e) {
return false;
}
$img->resizeImage($size_w, $size_h, Imagick::FILTER_LANCZOS, true);
$result = $img->writeImage($path);
return $result ? $path : false;
break;
case 'gd':
$img = self::gdImageCreate($path, $s['mime']);
if ($img && false != ($tmp = imagecreatetruecolor($size_w, $size_h))) {
self::gdImageBackground($tmp, $this->options['tmbBgColor']);
if (!imagecopyresampled($tmp, $img, 0, 0, 0, 0, $size_w, $size_h, $s[0], $s[1])) {
return false;
}
$result = self::gdImage($tmp, $path, $destformat, $s['mime']);
imagedestroy($img);
imagedestroy($tmp);
return $result ? $path : false;
}
break;
}
return false;
}