1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHP Exif Resolution ValueObject |
4
|
|
|
* |
5
|
|
|
* @link http://github.com/PHPExif/php-exif-common for the canonical source repository |
6
|
|
|
* @copyright Copyright (c) 2016 Tom Van Herreweghe <[email protected]> |
7
|
|
|
* @license http://github.com/PHPExif/php-exif-common/blob/master/LICENSE MIT License |
8
|
|
|
* @category PHPExif |
9
|
|
|
* @package Common |
10
|
|
|
* @codeCoverageIgnore |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace PHPExif\Common\Data\ValueObject; |
14
|
|
|
|
15
|
|
|
use \InvalidArgumentException; |
16
|
|
|
use \JsonSerializable; |
17
|
|
|
use \RuntimeException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Resolution class |
21
|
|
|
* |
22
|
|
|
* A value object to describe the resolution of an image |
23
|
|
|
* |
24
|
|
|
* @category PHPExif |
25
|
|
|
* @package Common |
26
|
|
|
*/ |
27
|
|
|
class Resolution implements JsonSerializable |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* The horizontal line resolution |
31
|
|
|
* |
32
|
|
|
* @var LineResolution |
33
|
|
|
*/ |
34
|
|
|
private $horizontal; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The vertical line resolution |
38
|
|
|
* |
39
|
|
|
* @var LineResolution |
40
|
|
|
*/ |
41
|
|
|
private $vertical; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param LineResolution $horizontal |
45
|
|
|
* @param LineResolution $vertical |
46
|
|
|
*/ |
47
|
|
|
public function __construct(LineResolution $horizontal, LineResolution $vertical) |
48
|
|
|
{ |
49
|
|
|
$this->setHorizontal($horizontal); |
50
|
|
|
$this->setVertical($vertical); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Sets the horizontal resolution |
55
|
|
|
* |
56
|
|
|
* @param LineResolution $horizontal |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
private function setHorizontal(LineResolution $horizontal) |
61
|
|
|
{ |
62
|
|
|
$this->horizontal = $horizontal; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Sets the vertical resolution |
67
|
|
|
* |
68
|
|
|
* @param LineResolution $vertical |
69
|
|
|
* |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
private function setVertical(LineResolution $vertical) |
73
|
|
|
{ |
74
|
|
|
$this->vertical = $vertical; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Getter for horizontal |
79
|
|
|
* |
80
|
|
|
* @return LineResolution |
81
|
|
|
*/ |
82
|
|
|
public function getHorizontalResolution() |
83
|
|
|
{ |
84
|
|
|
return $this->horizontal; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Getter for vertical |
89
|
|
|
* |
90
|
|
|
* @return LineResolution |
91
|
|
|
*/ |
92
|
|
|
public function getVerticalResolution() |
93
|
|
|
{ |
94
|
|
|
return $this->vertical; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Creates a new instance from given Resolution object |
99
|
|
|
* |
100
|
|
|
* @param Resolution $resolution |
101
|
|
|
* |
102
|
|
|
* @return Resolution |
103
|
|
|
*/ |
104
|
|
|
public static function fromResolution(Resolution $resolution) |
105
|
|
|
{ |
106
|
|
|
return new self( |
107
|
|
|
(clone $resolution->getHorizontalResolution()), |
108
|
|
|
(clone $resolution->getVerticalResolution()) |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @inheritDoc |
114
|
|
|
* |
115
|
|
|
* @return string |
116
|
|
|
*/ |
117
|
|
|
public function jsonSerialize() |
118
|
|
|
{ |
119
|
|
|
return [ |
120
|
|
|
'horizontal' => $this->getHorizontalResolution(), |
121
|
|
|
'vertical' => $this->getVerticalResolution(), |
122
|
|
|
]; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Returns string representation |
127
|
|
|
* |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
public function __toString() |
131
|
|
|
{ |
132
|
|
|
return sprintf( |
133
|
|
|
'%1$s x %2$s', |
134
|
|
|
(string) $this->getHorizontalResolution(), |
135
|
|
|
(string) $this->getVerticalResolution() |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|