1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* This file is part of the O2System Framework package.
|
4
|
|
|
*
|
5
|
|
|
* For the full copyright and license information, please view the LICENSE
|
6
|
|
|
* file that was distributed with this source code.
|
7
|
|
|
*
|
8
|
|
|
* @author Steeve Andrian Salim
|
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim
|
10
|
|
|
*/
|
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------
|
13
|
|
|
|
14
|
|
|
namespace O2System\Image;
|
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------
|
17
|
|
|
|
18
|
|
|
use O2System\Spl\DataStructures\SplArrayObject;
|
19
|
|
|
|
20
|
|
|
/**
|
21
|
|
|
* Class File
|
22
|
|
|
*
|
23
|
|
|
* @package O2System\Image\DataStructures
|
24
|
|
|
*/
|
25
|
|
|
class File extends \O2System\Filesystem\File
|
26
|
|
|
{
|
27
|
|
|
/**
|
28
|
|
|
* File::$dimension
|
29
|
|
|
*
|
30
|
|
|
* Image file dimension.
|
31
|
|
|
*
|
32
|
|
|
* @var Dimension
|
33
|
|
|
*/
|
34
|
|
|
private $dimension;
|
35
|
|
|
|
36
|
|
|
/**
|
37
|
|
|
* File::$bits
|
38
|
|
|
*
|
39
|
|
|
* Image bits.
|
40
|
|
|
*
|
41
|
|
|
* @var int
|
42
|
|
|
*/
|
43
|
|
|
private $bits;
|
44
|
|
|
|
45
|
|
|
/**
|
46
|
|
|
* File::$channels
|
47
|
|
|
*
|
48
|
|
|
* Image channels.
|
49
|
|
|
*
|
50
|
|
|
* @var int
|
51
|
|
|
*/
|
52
|
|
|
private $channels;
|
53
|
|
|
|
54
|
|
|
/**
|
55
|
|
|
* File::$type
|
56
|
|
|
*
|
57
|
|
|
* Image type.
|
58
|
|
|
*
|
59
|
|
|
* @var int
|
60
|
|
|
*/
|
61
|
|
|
private $type;
|
62
|
|
|
|
63
|
|
|
// ------------------------------------------------------------------------
|
64
|
|
|
|
65
|
|
|
/**
|
66
|
|
|
* File::__construct
|
67
|
|
|
*
|
68
|
|
|
* @param string $filePath
|
69
|
|
|
*/
|
70
|
|
|
public function __construct($filePath)
|
71
|
|
|
{
|
72
|
|
|
parent::__construct($filePath);
|
73
|
|
|
|
74
|
|
|
// Set image file properties
|
75
|
|
|
if (false !== ($imageSize = getimagesize($filePath))) {
|
76
|
|
|
$this->dimension = new Dimension($imageSize[ 0 ], $imageSize[ 1 ]);
|
77
|
|
|
$this->bits = $imageSize[ 'bits' ];
|
78
|
|
|
$this->channels = isset($imageSize[ 'channels' ]) ? $imageSize[ 'channels' ] : 0;
|
79
|
|
|
$this->type = $imageSize[ 2 ];
|
80
|
|
|
}
|
81
|
|
|
}
|
82
|
|
|
|
83
|
|
|
// ------------------------------------------------------------------------
|
84
|
|
|
|
85
|
|
|
/**
|
86
|
|
|
* File::getSize
|
87
|
|
|
*
|
88
|
|
|
* Gets image size.
|
89
|
|
|
*
|
90
|
|
|
* @return Dimension
|
91
|
|
|
*/
|
92
|
|
|
public function getDimension()
|
93
|
|
|
{
|
94
|
|
|
return $this->dimension;
|
95
|
|
|
}
|
96
|
|
|
|
97
|
|
|
// ------------------------------------------------------------------------
|
98
|
|
|
|
99
|
|
|
/**
|
100
|
|
|
* File::withDimension
|
101
|
|
|
*
|
102
|
|
|
* Gets new image file with new sets of dimension.
|
103
|
|
|
*
|
104
|
|
|
* @param Dimension $dimension New image dimension.
|
105
|
|
|
*
|
106
|
|
|
* @return \O2System\Image\File
|
107
|
|
|
*/
|
108
|
|
|
public function withDimension(Dimension $dimension)
|
109
|
|
|
{
|
110
|
|
|
$newFile = clone $this;
|
111
|
|
|
$newFile->dimension = $dimension;
|
112
|
|
|
|
113
|
|
|
return $newFile;
|
114
|
|
|
}
|
115
|
|
|
|
116
|
|
|
// ------------------------------------------------------------------------
|
117
|
|
|
|
118
|
|
|
/**
|
119
|
|
|
* File::getBits
|
120
|
|
|
*
|
121
|
|
|
* Gets image bits.
|
122
|
|
|
*
|
123
|
|
|
* @return int
|
124
|
|
|
*/
|
125
|
|
|
public function getBits()
|
126
|
|
|
{
|
127
|
|
|
return $this->bits;
|
128
|
|
|
}
|
129
|
|
|
|
130
|
|
|
// ------------------------------------------------------------------------
|
131
|
|
|
|
132
|
|
|
/**
|
133
|
|
|
* File::getChannels
|
134
|
|
|
*
|
135
|
|
|
* Gets image channels.
|
136
|
|
|
*
|
137
|
|
|
* @return int
|
138
|
|
|
*/
|
139
|
|
|
public function getChannels()
|
140
|
|
|
{
|
141
|
|
|
return $this->channels;
|
142
|
|
|
}
|
143
|
|
|
|
144
|
|
|
// ------------------------------------------------------------------------
|
145
|
|
|
|
146
|
|
|
/**
|
147
|
|
|
* File::getType
|
148
|
|
|
*
|
149
|
|
|
* Gets image type.
|
150
|
|
|
*
|
151
|
|
|
* @return int
|
152
|
|
|
*/
|
153
|
|
|
public function getType()
|
154
|
|
|
{
|
155
|
|
|
return $this->type;
|
156
|
|
|
}
|
157
|
|
|
|
158
|
|
|
// ------------------------------------------------------------------------
|
159
|
|
|
|
160
|
|
|
/**
|
161
|
|
|
* File::getExif
|
162
|
|
|
*
|
163
|
|
|
* Gets image exif.
|
164
|
|
|
*
|
165
|
|
|
* @return SplArrayObject|bool
|
166
|
|
|
*/
|
167
|
|
|
public function getExif()
|
168
|
|
|
{
|
169
|
|
|
if (false !== ($exifData = exif_read_data($this->getRealPath()))) {
|
170
|
|
|
return new SplArrayObject($exifData);
|
171
|
|
|
}
|
172
|
|
|
|
173
|
|
|
return false;
|
174
|
|
|
}
|
175
|
|
|
} |