mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: Correctly paddedResize images in IMagickBackend.
FIX: Compression quality setting now takes effect. fixes #3333
This commit is contained in:
parent
47cc157d97
commit
02265dc3c4
@ -23,9 +23,8 @@ class ImagickBackend extends Imagick implements Image_Backend {
|
|||||||
public function __construct($filename = null) {
|
public function __construct($filename = null) {
|
||||||
if(is_string($filename)) {
|
if(is_string($filename)) {
|
||||||
parent::__construct($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
|
* @return Image_Backend
|
||||||
*/
|
*/
|
||||||
public function paddedResize($width, $height, $backgroundColor = "FFFFFF") {
|
public function paddedResize($width, $height, $backgroundColor = "FFFFFF") {
|
||||||
if(!$this->valid()) return;
|
$new = $this->resizeRatio($width, $height);
|
||||||
|
$new->setImageBackgroundColor("#".$backgroundColor);
|
||||||
$width = round($width);
|
$w = $new->getImageWidth();
|
||||||
$height = round($height);
|
$h = $new->getImageHeight();
|
||||||
$geometry = $this->getImageGeometry();
|
$new->extentImage($width,$height,($w-$width)/2,($h-$height)/2);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $new;
|
return $new;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user