Skip to content

Commit

Permalink
Fixed pad problem when used without color specified. Fixes #222
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebacker committed Jun 11, 2024
1 parent 18c9489 commit 09dc88f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function resizeAndOrCrop(?int $width, ?int $height, array $options = []):
if (isset($options['quadrant'])) {
return $this->cropQuadrant($width, $height, $options);
}
if (array_key_exists('pad', $options)) {
if (isset($options['pad']) || in_array('pad', $options)) {
$this->pad($width, $height, $options);
}
if (array_key_exists('resize', $options) || !$width || !$height) {
Expand Down Expand Up @@ -207,10 +207,8 @@ public function pad(?int $width, ?int $height, array $options): self
if (!$height || !$width) {
throw new Exception('Croppa: Pad option needs width and height');
}
if (!isset($options['pad'])) {
throw new Exception('Croppa: No pad color specified');
}
$rgbArray = $options['pad'] ?: [255, 255, 255];

$rgbArray = $options['pad'] ?? [255, 255, 255];
$color = sprintf("#%02x%02x%02x", $rgbArray[0], $rgbArray[1], $rgbArray[2]);

if (!$this->upsize) {
Expand Down
11 changes: 11 additions & 0 deletions tests/TestResizing.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ public function testWidthAndHeightPad()
$this->assertEquals('200x200', $size[0].'x'.$size[1]);
}

public function testWidthAndHeightAndPadWithoutColor()
{
$image = new Image($this->src, $this->options);
$imageString = $image->process(200, 200, ['pad'])->get();
$size = getimagesizefromstring($imageString);
$firstPixelColor = ImageManager::gd()->read($imageString)->pickColor(1, 1)->toHex();

$this->assertEquals('ffffff', $firstPixelColor);
$this->assertEquals('200x200', $size[0].'x'.$size[1]);
}

public function testWidthAndHeightTrim()
{
$image = new Image($this->src, $this->options);
Expand Down

0 comments on commit 09dc88f

Please sign in to comment.