diff --git a/src/Transformation/Background/BackgroundTrait.php b/src/Transformation/Background/BackgroundTrait.php index 2dba6cc..536cc03 100644 --- a/src/Transformation/Background/BackgroundTrait.php +++ b/src/Transformation/Background/BackgroundTrait.php @@ -26,7 +26,7 @@ trait BackgroundTrait * The image background is visible when padding is added with one of the padding crop modes, when rounding corners, * when adding overlays, and with semi-transparent PNGs and GIFs. * - * @param Background|ColorValue|string $background The the background to set. + * @param Background|ColorValue|string $background The background to set. * * @return $this * diff --git a/src/Transformation/Resize/Crop/CropPad.php b/src/Transformation/Resize/Crop/CropPad.php new file mode 100644 index 0000000..695a491 --- /dev/null +++ b/src/Transformation/Resize/Crop/CropPad.php @@ -0,0 +1,64 @@ +background($background); + } + + /** + * Sets the gravity to use when using the FILL_PAD crop mode. + * + * @param $autoGravity + * + * @return $this + */ + public function gravity($autoGravity) + { + if (! $autoGravity instanceof AutoGravity) { + throw new InvalidArgumentException('CropPad only supports Auto Gravity'); + } + + $this->addQualifier($autoGravity); + + return $this; + } +} diff --git a/src/Transformation/Resize/Crop/CropPadTrait.php b/src/Transformation/Resize/Crop/CropPadTrait.php new file mode 100644 index 0000000..95be1cf --- /dev/null +++ b/src/Transformation/Resize/Crop/CropPadTrait.php @@ -0,0 +1,44 @@ +zoom(0.5) + ); + + self::assertStrEquals( + 'c_auto_pad,g_auto:dog,h_200,w_100', + CropPad::autoPad(100, 200, Gravity::auto()->autoFocus(FocusOn::dog())) + ); + + self::assertStrEquals( + 'b_gen_fill,c_auto_pad,g_auto:dog,h_200,w_100', + CropPad::autoPad(100, 200, Gravity::auto()->autoFocus(FocusOn::dog()))->background( + Background::generativeFill() + ) + ); + } + public function testResize() { /** @noinspection PhpUndefinedMethodInspection */ @@ -303,5 +331,10 @@ public function testResize() 'c_crop,h_70,w_50,z_0.5', (string)Resize::crop(50, 70)->zoom(0.5) ); + + self::assertStrEquals( + 'b_gen_fill,c_auto_pad,g_auto:dog,h_200,w_100', + Resize::autoPad(100, 200, Gravity::auto()->autoFocus(FocusOn::dog()), Background::generativeFill()) + ); } }