From 47cc157d976a0bf1fae62ef491cad9fe3e1e2c99 Mon Sep 17 00:00:00 2001 From: Jeremy Shipman Date: Mon, 28 Jul 2014 11:57:32 +1200 Subject: [PATCH 1/2] FIX: Keep ImagickBackend API consistent with Image_Backend interface and fix color formatting. --- filesystem/ImagickBackend.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/filesystem/ImagickBackend.php b/filesystem/ImagickBackend.php index 000d366ec..c5f356452 100644 --- a/filesystem/ImagickBackend.php +++ b/filesystem/ImagickBackend.php @@ -184,7 +184,7 @@ class ImagickBackend extends Imagick implements Image_Backend { * @param int $height * @return Image_Backend */ - public function paddedResize($width, $height, $backgroundColor = "#FFFFFF00") { + public function paddedResize($width, $height, $backgroundColor = "FFFFFF") { if(!$this->valid()) return; $width = round($width); @@ -197,7 +197,7 @@ class ImagickBackend extends Imagick implements Image_Backend { } $new = clone $this; - $new->setBackgroundColor($backgroundColor); + $new->setBackgroundColor("#".$backgroundColor); $destAR = $width / $height; if ($geometry["width"] > 0 && $geometry["height"] > 0) { From 02265dc3c4a6d2fca20773edb5ac0938574d5d68 Mon Sep 17 00:00:00 2001 From: Jeremy Shipman Date: Mon, 28 Jul 2014 12:19:34 +1200 Subject: [PATCH 2/2] FIX: Correctly paddedResize images in IMagickBackend. FIX: Compression quality setting now takes effect. fixes #3333 --- filesystem/ImagickBackend.php | 47 +++++------------------------------ 1 file changed, 6 insertions(+), 41 deletions(-) diff --git a/filesystem/ImagickBackend.php b/filesystem/ImagickBackend.php index c5f356452..729042363 100644 --- a/filesystem/ImagickBackend.php +++ b/filesystem/ImagickBackend.php @@ -23,9 +23,8 @@ class ImagickBackend extends Imagick implements Image_Backend { public function __construct($filename = null) { if(is_string($filename)) { parent::__construct($filename); - } else { - self::setImageCompressionQuality($this->config()->default_quality); } + $this->setQuality(Config::inst()->get('ImagickBackend','default_quality')); } /** @@ -185,45 +184,11 @@ class ImagickBackend extends Imagick implements Image_Backend { * @return Image_Backend */ public function paddedResize($width, $height, $backgroundColor = "FFFFFF") { - if(!$this->valid()) return; - - $width = round($width); - $height = round($height); - $geometry = $this->getImageGeometry(); - - // Check that a resize is actually necessary. - if ($width == $geometry["width"] && $height == $geometry["height"]) { - return $this; - } - - $new = clone $this; - $new->setBackgroundColor("#".$backgroundColor); - - $destAR = $width / $height; - if ($geometry["width"] > 0 && $geometry["height"] > 0) { - // We can't divide by zero theres something wrong. - - $srcAR = $geometry["width"] / $geometry["height"]; - - // Destination narrower than the source - if($destAR > $srcAR) { - $destY = 0; - $destHeight = $height; - - $destWidth = round( $height * $srcAR ); - $destX = round( ($width - $destWidth) / 2 ); - - // Destination shorter than the source - } else { - $destX = 0; - $destWidth = $width; - - $destHeight = round( $width / $srcAR ); - $destY = round( ($height - $destHeight) / 2 ); - } - - $new->extentImage($width, $height, $destX, $destY); - } + $new = $this->resizeRatio($width, $height); + $new->setImageBackgroundColor("#".$backgroundColor); + $w = $new->getImageWidth(); + $h = $new->getImageHeight(); + $new->extentImage($width,$height,($w-$width)/2,($h-$height)/2); return $new; }