File tree Expand file tree Collapse file tree 4 files changed +78
-1
lines changed Expand file tree Collapse file tree 4 files changed +78
-1
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ final class Optimole
33
33
/**
34
34
* The Optimole SDK version.
35
35
*/
36
- public const VERSION = '1.2.1 ' ;
36
+ public const VERSION = '1.2.2 ' ;
37
37
38
38
/**
39
39
* The Optimole dashboard API URL.
Original file line number Diff line number Diff line change 17
17
18
18
class Image extends AbstractResource
19
19
{
20
+ /**
21
+ * Set the dpr of the optimized image.
22
+ */
23
+ public function dpr ($ dpr = 1 ): self
24
+ {
25
+ $ this ->addProperty (new ImageProperty \DprProperty ($ dpr ));
26
+
27
+ return $ this ;
28
+ }
29
+
20
30
/**
21
31
* Convert the optimized image to the given format.
22
32
*/
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ /*
6
+ * This file is part of Optimole PHP SDK.
7
+ *
8
+ * (c) Optimole Team <[email protected] >
9
+ *
10
+ * For the full copyright and license information, please view the LICENSE
11
+ * file that was distributed with this source code.
12
+ */
13
+
14
+ namespace Optimole \Sdk \Resource \ImageProperty ;
15
+
16
+ use Optimole \Sdk \Exception \InvalidArgumentException ;
17
+ use Optimole \Sdk \Resource \PropertyInterface ;
18
+
19
+ class DprProperty implements PropertyInterface
20
+ {
21
+ /**
22
+ * The dpr of the image.
23
+ */
24
+ private $ dpr ;
25
+
26
+ /**
27
+ * Constructor.
28
+ */
29
+ public function __construct ($ dpr = 1 )
30
+ {
31
+ if (!is_int ($ dpr ) || $ dpr < 1 ) {
32
+ throw new InvalidArgumentException ('Image dpr must be an integer greater or equal than 1. ' );
33
+ }
34
+ $ dpr = max (1 , min (5 , $ dpr ));
35
+
36
+ $ this ->dpr = $ dpr ;
37
+ }
38
+
39
+ /**
40
+ * {@inheritdoc}
41
+ */
42
+ public function __toString (): string
43
+ {
44
+ return sprintf ('dpr:%s ' , $ this ->dpr );
45
+ }
46
+ }
Original file line number Diff line number Diff line change 19
19
20
20
class ImageTest extends TestCase
21
21
{
22
+ public function testDprAddsDprPropriety (): void
23
+ {
24
+ $ image = (new Image ('domain ' , 'source ' ))->dpr (2 );
25
+
26
+ $ this ->assertSame ('https://domain/dpr:2/source ' , (string ) $ image );
27
+ }
28
+
29
+ public function testDprAddsDprProprietyDefault (): void
30
+ {
31
+ $ image = (new Image ('domain ' , 'source ' ))->dpr (1 );
32
+
33
+ $ this ->assertSame ('https://domain/dpr:1/source ' , (string ) $ image );
34
+ }
35
+
36
+ public function testDprAddsDprProprietyHigh (): void
37
+ {
38
+ $ image = (new Image ('domain ' , 'source ' ))->dpr (10 );
39
+
40
+ $ this ->assertSame ('https://domain/dpr:5/source ' , (string ) $ image );
41
+ }
42
+
22
43
public function testFormatAddsFormatProperty (): void
23
44
{
24
45
$ image = (new Image ('domain ' , 'source ' ))->format ('webp ' );
You can’t perform that action at this time.
0 commit comments