Skip to content

Commit

Permalink
Add support for blurFaces and blurRegion effects
Browse files Browse the repository at this point in the history
  • Loading branch information
const-cloudinary committed May 27, 2024
1 parent a88d355 commit d6ee8ee
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Transformation/Effect/Pixel/PixelEffectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/Transformation/Common/EffectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down

0 comments on commit d6ee8ee

Please sign in to comment.