-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathResizeConfiguration.php
128 lines (100 loc) · 2.69 KB
/
ResizeConfiguration.php
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
declare(strict_types=1);
/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/
namespace Contao\Image;
use Contao\Image\Exception\InvalidArgumentException;
class ResizeConfiguration
{
public const MODE_CROP = 'crop';
public const MODE_BOX = 'box';
/**
* @deprecated Deprecated since version 1.2, to be removed in version 2.0.
*/
public const MODE_PROPORTIONAL = 'proportional';
/**
* @var int
*/
private $width = 0;
/**
* @var int
*/
private $height = 0;
/**
* @var string
*/
private $mode = self::MODE_CROP;
/**
* @var int
*/
private $zoomLevel = 0;
/**
* Returns true if the resize would have no effect.
*/
public function isEmpty(): bool
{
return 0 === $this->width && 0 === $this->height && 0 === $this->zoomLevel;
}
public function getWidth(): int
{
return $this->width;
}
public function setWidth(int $width): self
{
if ($width < 0) {
throw new InvalidArgumentException('Width must not be negative');
}
$this->width = $width;
return $this;
}
public function getHeight(): int
{
return $this->height;
}
public function setHeight(int $height): self
{
if ($height < 0) {
throw new InvalidArgumentException('Height must not be negative');
}
$this->height = $height;
return $this;
}
/**
* @return string One of the ResizeConfiguration::MODE_* constants
*/
public function getMode(): string
{
return $this->mode;
}
/**
* @param string $mode One of the ResizeConfiguration::MODE_* constants
*/
public function setMode(string $mode): self
{
if (!\in_array($mode, [self::MODE_CROP, self::MODE_BOX, self::MODE_PROPORTIONAL], true)) {
throw new InvalidArgumentException('Mode must be one of the '.self::class.'::MODE_* constants');
}
if (self::MODE_PROPORTIONAL === $mode) {
trigger_deprecation('contao/image', '1.2', 'Using ResizeConfiguration::MODE_PROPORTIONAL has been deprecated and will no longer work in version 2.0. Use ResizeConfiguration::MODE_BOX instead.');
}
$this->mode = $mode;
return $this;
}
public function getZoomLevel(): int
{
return $this->zoomLevel;
}
public function setZoomLevel(int $zoomLevel): self
{
if ($zoomLevel < 0 || $zoomLevel > 100) {
throw new InvalidArgumentException('Zoom level must be between 0 and 100');
}
$this->zoomLevel = $zoomLevel;
return $this;
}
}