Skip to content

Commit 6cf2cb9

Browse files
Add support for DropShadow effect
Co-authored-by: carlevison <54800761+carlevison@users.noreply.github.com>
1 parent fd02b1f commit 6cf2cb9

File tree

6 files changed

+212
-2
lines changed

6 files changed

+212
-2
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* This file is part of the Cloudinary PHP package.
4+
*
5+
* (c) Cloudinary
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Cloudinary\Transformation;
12+
13+
/**
14+
* Class DropShadow
15+
*/
16+
class DropShadow extends EffectAction
17+
{
18+
/**
19+
* DropShadow constructor.
20+
*
21+
* @param int $azimuth Value in range 0 - 360 (degrees).
22+
* @param int $elevation Value in range 0 - 90 (degrees).
23+
* @param int $spread Value in range 0 -100.
24+
*/
25+
public function __construct($azimuth = null, $elevation = null, $spread = null)
26+
{
27+
parent::__construct(new DropShadowQualifier($azimuth, $elevation, $spread));
28+
}
29+
30+
/**
31+
* Sets the direction the light is coming from to cause the shadow effect.
32+
*
33+
* @param int $azimuth Value in range 0 - 360 (degrees).
34+
*
35+
* @return $this
36+
*/
37+
public function azimuth($azimuth)
38+
{
39+
$this->getMainQualifier()->azimuth($azimuth);
40+
41+
return $this;
42+
}
43+
44+
/**
45+
* Sets the height of the light source above the 'ground' to cause the shadow effect.
46+
*
47+
* @param int $elevation Value in range 0 - 90 (degrees).
48+
*
49+
* @return $this
50+
*/
51+
public function elevation($elevation)
52+
{
53+
$this->getMainQualifier()->elevation($elevation);
54+
55+
return $this;
56+
}
57+
58+
/**
59+
* Sets the spread of the light source. A small number means 'point' light. A larger number means 'area' light.
60+
*
61+
* @param int $spread Value in range 0 -100.
62+
*
63+
* @return $this
64+
*/
65+
public function spread($spread)
66+
{
67+
$this->getMainQualifier()->spread($spread);
68+
69+
return $this;
70+
}
71+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* This file is part of the Cloudinary PHP package.
4+
*
5+
* (c) Cloudinary
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Cloudinary\Transformation;
12+
13+
/**
14+
* Class DropShadowQualifier
15+
*/
16+
class DropShadowQualifier extends EffectQualifier
17+
{
18+
/**
19+
* DropShadowQualifier constructor.
20+
*
21+
* @param int $azimuth Value in range 0 - 360 (degrees).
22+
* @param int $elevation Value in range 0 - 90 (degrees).
23+
* @param int $spread Value in range 0 -100.
24+
*/
25+
public function __construct($azimuth = null, $elevation = null, $spread = null)
26+
{
27+
parent::__construct(MiscEffect::DROP_SHADOW);
28+
29+
$this->value->setSimpleValue('properties', new ListExpressionQualifierMultiValue());
30+
31+
$this->azimuth($azimuth);
32+
$this->elevation($elevation);
33+
$this->spread($spread);
34+
}
35+
36+
/**
37+
* Sets the direction the light is coming from to cause the shadow effect.
38+
*
39+
* @param int $azimuth Value in range 0 - 360 (degrees).
40+
*
41+
* @return $this
42+
*/
43+
public function azimuth($azimuth)
44+
{
45+
$this->value->getSimpleValue('properties')->setSimpleNamedValue('azimuth', $azimuth);
46+
47+
return $this;
48+
}
49+
50+
/**
51+
* Sets the height of the light source above the 'ground' to cause the shadow effect.
52+
*
53+
* @param int $elevation Value in range 0 - 90 (degrees).
54+
*
55+
* @return $this
56+
*/
57+
public function elevation($elevation)
58+
{
59+
$this->value->getSimpleValue('properties')->setSimpleNamedValue('elevation', $elevation);
60+
61+
return $this;
62+
}
63+
64+
/**
65+
* Sets the spread of the light source. A small number means 'point' light. A larger number means 'area' light.
66+
*
67+
* @param int $spread Value in range 0 -100.
68+
*
69+
* @return $this
70+
*/
71+
public function spread($spread)
72+
{
73+
$this->value->getSimpleValue('properties')->setSimpleNamedValue('spread', $spread);
74+
75+
return $this;
76+
}
77+
}

src/Transformation/Effect/Misc/MiscEffect.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ abstract class MiscEffect
2323
const ADVANCED_RED_EYE = 'adv_redeye';
2424
const VECTORIZE = 'vectorize';
2525
const OUTLINE = 'outline';
26+
const DROP_SHADOW = 'dropshadow';
2627
}

src/Transformation/Effect/Misc/MiscEffectTrait.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,20 @@ public static function shadow($strength = null, $position = null, $color = null)
185185
{
186186
return new Shadow($strength, $position, $color);
187187
}
188+
189+
/**
190+
* Adds a natural looking shadow to an image.
191+
*
192+
* @param int $azimuth Value in range 0 - 360 (degrees).
193+
* @param int $elevation Value in range 0 - 90 (degrees).
194+
* @param int $spread Value in range 0 -100.
195+
*
196+
* @return DropShadow
197+
*
198+
* @see \Cloudinary\Transformation\DropShadow
199+
*/
200+
public static function dropShadow($azimuth = null, $elevation = null, $spread = null)
201+
{
202+
return new DropShadow($azimuth, $elevation, $spread);
203+
}
188204
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* This file is part of the Cloudinary PHP package.
4+
*
5+
* (c) Cloudinary
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Cloudinary\Transformation;
12+
13+
use Cloudinary\Transformation\Qualifier\BaseQualifier;
14+
15+
/**
16+
* Class ListExpressionQualifierMultiValue
17+
*
18+
* This class represents a complex list expression value of the cloudinary transformation qualifier.
19+
*
20+
* @used-by BaseQualifier
21+
*/
22+
class ListExpressionQualifierMultiValue extends ExpressionQualifierMultiValue
23+
{
24+
const VALUE_DELIMITER = ';';
25+
}

tests/Unit/Transformation/Common/EffectTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
namespace Cloudinary\Test\Unit\Transformation\Common;
1212

13+
use Cloudinary\Test\TransformationTestCase;
1314
use Cloudinary\Transformation\Argument\Color;
1415
use Cloudinary\Transformation\Argument\PointValue;
1516
use Cloudinary\Transformation\ArtisticFilter;
@@ -27,12 +28,11 @@
2728
use Cloudinary\Transformation\WhiteBalance;
2829
use Cloudinary\Transformation\Xmp;
2930
use OutOfRangeException;
30-
use PHPUnit\Framework\TestCase;
3131

3232
/**
3333
* Class SampleTest
3434
*/
35-
final class EffectTest extends TestCase
35+
final class EffectTest extends TransformationTestCase
3636
{
3737
protected $effectLevel = 17;
3838
protected $effectNegativeLevel = -17;
@@ -298,6 +298,26 @@ public function testShadow()
298298
);
299299
}
300300

301+
public function testDropShadow()
302+
{
303+
self::assertStrEquals(
304+
'e_dropshadow',
305+
Effect::dropShadow()
306+
);
307+
self::assertStrEquals(
308+
'e_dropshadow:elevation_11',
309+
Effect::dropShadow()->elevation(11)
310+
);
311+
self::assertEquals(
312+
'e_dropshadow:azimuth_10;elevation_11;spread_12',
313+
Effect::dropShadow()->azimuth(10)->elevation(11)->spread(12)
314+
);
315+
self::assertEquals(
316+
'e_dropshadow:azimuth_10;elevation_11;spread_12',
317+
Effect::dropShadow()->spread(12)->elevation(11)->azimuth(10)
318+
);
319+
}
320+
301321
public function testTrimImageEffect()
302322
{
303323
self::assertEquals(

0 commit comments

Comments
 (0)