PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 4.2.11
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v4.2.11
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 / ImageProperty / WatermarkProperty.php

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

99 lines 2.3 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\ImageProperty;
15
16 use Optimole\Sdk\Exception\InvalidArgumentException;
17 use Optimole\Sdk\Resource\PropertyInterface;
18 use Optimole\Sdk\ValueObject\Position;
19
20 class WatermarkProperty implements PropertyInterface
21 {
22 /**
23 * The watermark ID in Optimole.
24 */
25 private int $id;
26
27 /**
28 * The horizontal offset of the watermark.
29 */
30 private float $offsetX;
31
32 /**
33 * The vertical offset of the watermark.
34 */
35 private float $offsetY;
36
37 /**
38 * The opacity of the watermark.
39 */
40 private float $opacity;
41
42 /**
43 * The position of the watermark.
44 */
45 private Position $position;
46
47 /**
48 * Defines the watermark size relative to the resultant image size.
49 */
50 private float $scale;
51
52 /**
53 * Constructor.
54 */
55 public function __construct(int $id, float $opacity, $position, float $offsetX = 0, float $offsetY = 0, float $scale = 0)
56 {
57 if (!is_string($position) && !$position instanceof Position) {
58 throw new InvalidArgumentException('Watermark position must be a string or an instance of Position.');
59 } elseif (is_string($position)) {
60 $position = new Position($position);
61 }
62
63 $this->id = $id;
64 $this->offsetX = $offsetX;
65 $this->offsetY = $offsetY;
66 $this->opacity = $opacity;
67 $this->position = $position;
68 $this->scale = $scale;
69 }
70
71 /**
72 * {@inheritdoc}
73 */
74 public function __toString(): string
75 {
76 $watermark = sprintf('wm:%s:%s:%s', $this->id, $this->opacity, $this->position);
77
78 if (empty($this->offsetX)) {
79 return $watermark;
80 }
81
82 $watermark .= sprintf(':%s', $this->offsetX);
83
84 if (empty($this->offsetY)) {
85 return $watermark;
86 }
87
88 $watermark .= sprintf(':%s', $this->offsetY);
89
90 if (empty($this->scale)) {
91 return $watermark;
92 }
93
94 $watermark .= sprintf(':%s', $this->scale);
95
96 return $watermark;
97 }
98 }
99