-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathInsertModifier.php
More file actions
49 lines (42 loc) Β· 1.32 KB
/
InsertModifier.php
File metadata and controls
49 lines (42 loc) Β· 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Alignment;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\InvalidArgumentException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\PointInterface;
class InsertModifier extends SpecializableModifier
{
/**
* Create new modifier object.
*
* @throws InvalidArgumentException
*/
public function __construct(
public mixed $image,
public int $x = 0,
public int $y = 0,
public string|Alignment $alignment = Alignment::TOP_LEFT,
public float $transparency = 1
) {
if ($this->transparency < 0 || $this->transparency > 1) {
throw new InvalidArgumentException('Transparency must be in range 0 to 1');
}
}
/**
* Calculate position of the watermark to be inserted on the image.
*/
public function position(ImageInterface $image, ImageInterface $watermark): PointInterface
{
$imageSize = $image->size()->movePivot(
$this->alignment,
$this->x,
$this->y
);
$watermarkSize = $watermark->size()->movePivot(
$this->alignment
);
return $imageSize->offsetTo($watermarkSize);
}
}