diff --git a/src/Image.php b/src/Image.php index cceaf45..fc4363d 100644 --- a/src/Image.php +++ b/src/Image.php @@ -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) { @@ -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) { diff --git a/tests/TestResizing.php b/tests/TestResizing.php index 6f64a6c..08a191a 100644 --- a/tests/TestResizing.php +++ b/tests/TestResizing.php @@ -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);