Skip to content

Commit

Permalink
Add a working "fill" mode to Image Resize Effect
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelAlphonso committed Feb 23, 2018
1 parent 6b7a851 commit dce39d8
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/Charcoal/Image/Effect/AbstractResizeEffect.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,26 @@ public function process(array $data = null)
);

case 'fill':
$imgClass = get_class($this->image());
$canvas = new $imgClass;
$canvas->create($this->width(), $this->width(), $this->backgroundColor());
throw new Exception(
'Crop resize mode is not (yet) supported'
);
$newWidth = $this->width();
$newHeight = $this->height();

$oldRatio = ($imageWidth / $imageHeight);
$newRatio = ($newWidth / $newHeight);

if ($newRatio > $oldRatio) {
$newHeight = ($imageHeight * $this->width() / $imageWidth);
} else {
$newWidth = ($imageWidth * $this->height() / $imageHeight);
}

$this->doResize($newWidth, $newHeight);

// $imgClass = get_class($this->image());
// $canvas = new $imgClass;
// $canvas->create($this->width(), $this->width(), $this->backgroundColor());
// throw new Exception(
// 'Crop resize mode is not (yet) supported'
// );
}

return $this;
Expand Down

0 comments on commit dce39d8

Please sign in to comment.