PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 4.2.12
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v4.2.12
4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 3.12.1 All 134 releases
optimole-wp / vendor / codeinwp / optimole-sdk / src / Resource / Image.php

Image.php in Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization 4.2.12, at vendor/codeinwp/optimole-sdk/src/Resource/Image.php

135 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 /*
6 * This file is part of Optimole PHP SDK.
7 *
8 * (c) Optimole Team <friends@optimole.com>
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;
15
16 use Optimole\Sdk\ValueObject\Position;
17
18 class Image extends AbstractResource
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
30 /**
31 * Convert the optimized image to the given format.
32 */
33 public function format(string $format): self
34 {
35 $this->addProperty(new ImageProperty\FormatProperty($format));
36
37 return $this;
38 }
39
40 /**
41 * Set the height of the optimized image.
42 */
43 public function height($height): self
44 {
45 $this->addProperty(new ImageProperty\HeightProperty($height));
46
47 return $this;
48 }
49
50 /**
51 * Ignore the AVIF format when optimizing the image.
52 */
53 public function ignoreAvif(): self
54 {
55 $this->addProperty(new ImageProperty\IgnoreAvifProperty());
56
57 return $this;
58 }
59
60 /**
61 * Keep the original image copyright in the optimized image.
62 */
63 public function keepCopyright(): self
64 {
65 $this->addProperty(new ImageProperty\KeepCopyrightProperty());
66
67 return $this;
68 }
69
70 /**
71 * Set the quality of the optimized image.
72 */
73 public function quality($quality = 'mauto'): self
74 {
75 $this->addProperty(new ImageProperty\QualityProperty($quality));
76
77 return $this;
78 }
79
80 /**
81 * Resize the optimized image.
82 */
83 public function resize(string $type, $gravity = Position::CENTER, bool $enlarge = false): self
84 {
85 $this->addProperty(new ImageProperty\ResizeTypeProperty($type));
86 $this->addProperty(new ImageProperty\GravityProperty($gravity));
87
88 if ($enlarge) {
89 $this->addProperty(new ImageProperty\EnlargeProperty());
90 }
91
92 return $this;
93 }
94
95 /**
96 * Set the smart focus gravity of the optimized image.
97 */
98 public function smartFocus()
99 {
100 $this->addProperty(new ImageProperty\GravityProperty('sm'));
101
102 return $this;
103 }
104
105 /**
106 * Whether to strip the original image metadata from the optimized image.
107 */
108 public function stripMetadata(bool $stripMetadata = true): self
109 {
110 $this->addProperty(new ImageProperty\StripMetadataProperty($stripMetadata));
111
112 return $this;
113 }
114
115 /**
116 * Apply a watermark to the optimized image.
117 */
118 public function watermark(int $id, float $opacity, $position = Position::CENTER, float $offsetX = 0, float $offsetY = 0, float $scale = 0): self
119 {
120 $this->addProperty(new ImageProperty\WatermarkProperty($id, $opacity, $position, $offsetX, $offsetY, $scale));
121
122 return $this;
123 }
124
125 /**
126 * Set the width of the optimized image.
127 */
128 public function width($width): self
129 {
130 $this->addProperty(new ImageProperty\WidthProperty($width));
131
132 return $this;
133 }
134 }
135