Skip to content

Commit dce39d8

Browse files
committed
Add a working "fill" mode to Image Resize Effect
1 parent 6b7a851 commit dce39d8

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/Charcoal/Image/Effect/AbstractResizeEffect.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,26 @@ public function process(array $data = null)
470470
);
471471

472472
case 'fill':
473-
$imgClass = get_class($this->image());
474-
$canvas = new $imgClass;
475-
$canvas->create($this->width(), $this->width(), $this->backgroundColor());
476-
throw new Exception(
477-
'Crop resize mode is not (yet) supported'
478-
);
473+
$newWidth = $this->width();
474+
$newHeight = $this->height();
475+
476+
$oldRatio = ($imageWidth / $imageHeight);
477+
$newRatio = ($newWidth / $newHeight);
478+
479+
if ($newRatio > $oldRatio) {
480+
$newHeight = ($imageHeight * $this->width() / $imageWidth);
481+
} else {
482+
$newWidth = ($imageWidth * $this->height() / $imageHeight);
483+
}
484+
485+
$this->doResize($newWidth, $newHeight);
486+
487+
// $imgClass = get_class($this->image());
488+
// $canvas = new $imgClass;
489+
// $canvas->create($this->width(), $this->width(), $this->backgroundColor());
490+
// throw new Exception(
491+
// 'Crop resize mode is not (yet) supported'
492+
// );
479493
}
480494

481495
return $this;

0 commit comments

Comments
 (0)