From d6ee8ee959851d88abdd3b59efa49562f20f6197 Mon Sep 17 00:00:00 2001 From: Constantine Nathanson Date: Mon, 27 May 2024 12:11:41 +0300 Subject: [PATCH] Add support for `blurFaces` and `blurRegion` effects --- .../Effect/Pixel/PixelEffectTrait.php | 28 +++++++++++++++++++ .../Unit/Transformation/Common/EffectTest.php | 25 +++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/Transformation/Effect/Pixel/PixelEffectTrait.php b/src/Transformation/Effect/Pixel/PixelEffectTrait.php index 3ceeb5c..49311cc 100644 --- a/src/Transformation/Effect/Pixel/PixelEffectTrait.php +++ b/src/Transformation/Effect/Pixel/PixelEffectTrait.php @@ -29,6 +29,34 @@ public static function blur($strength = null) return new Blur($strength); } + /** + * Applies a blurring filter to the faces detected on the asset. + * + * @param int $strength The strength of the blur. (Range: 1 to 2000, Server default: 100) + * + * @return Blur + */ + public static function blurFaces($strength = null) + { + return (new Blur($strength))->region(Region::faces()); + } + + /** + * Applies a blurring filter to the region on the asset. + * + * @param int|string $strength The strength of the blur. (Range: 1 to 2000, Server default: 100) + * @param int|string $x X. + * @param int|string $y Y. + * @param int|string $width Width. + * @param int|string $height Height. + * + * @return Blur + */ + public static function blurRegion($strength = null, $x = null, $y = null, $width = null, $height = null) + { + return (new Blur($strength))->region(Region::custom($x, $y, $width, $height)); + } + /** * Applies a vignette effect. * diff --git a/tests/Unit/Transformation/Common/EffectTest.php b/tests/Unit/Transformation/Common/EffectTest.php index 0b6653b..d69c674 100644 --- a/tests/Unit/Transformation/Common/EffectTest.php +++ b/tests/Unit/Transformation/Common/EffectTest.php @@ -225,6 +225,21 @@ public function testBlurEffects() (string)Effect::blur(2000)->region(Region::custom()->size('30x40')->position(10, 20)) ); + self::assertEquals( + 'e_blur_region:2000,h_40,w_30,x_10,y_20', + (string)Effect::blurRegion(2000, 10, 20, 30, 40) + ); + + self::assertEquals( + 'e_blur_region:2000,h_40,w_30,x_10,y_20', + (string)Effect::blurRegion()->strength(2000)->x(10)->y(20)->width(30)->height(40) + ); + + self::assertEquals( + 'e_blur_region:$var1,h_$var5,w_$var4,x_$var2,y_$var3', + (string)Effect::blurRegion()->strength('$var1')->x('$var2')->y('$var3')->width('$var4')->height('$var5') + ); + self::assertEquals( 'e_blur_faces:17', (string)Effect::blur(17)->region(Region::faces()) @@ -235,6 +250,16 @@ public function testBlurEffects() (string)Effect::blur()->strength(17)->region(Region::faces()) ); + self::assertEquals( + 'e_blur_faces:17', + (string)Effect::blurFaces(17) + ); + + self::assertEquals( + 'e_blur_faces:17', + (string)Effect::blurFaces()->strength(17) + ); + self::assertEquals( 'e_blur_region:17,g_ocr_text', (string)Effect::blur(17)->region(Region::ocr())