-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathImage.php
194 lines (167 loc) · 4.02 KB
/
Image.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
namespace dokuwiki\plugin\gallery\classes;
use dokuwiki\Utf8\PhpString;
class Image
{
public const IMG_REGEX = '/\.(jpe?g|gif|png|svg|webpi|mp4)$/i';
protected $isExternal = false;
protected $src;
protected $filename;
protected $localfile;
protected $title;
protected $description;
protected $width;
protected $height;
protected $created = 0;
protected $modified = 0;
protected $detaillink;
public $imagetype;
/**
* @param string $src local ID or external URL to image
* @throws \Exception
*/
public function __construct($src)
{
$this->src = $src;
if (preg_match('/^https:\/\//i', $src)) {
$this->isExternal = true;
$path = parse_url($src, PHP_URL_PATH);
$this->filename = basename($path);
} else {
$this->localfile = mediaFN($src);
if (!file_exists($this->localfile)) throw new \Exception('File not found: ' . $this->localfile);
$this->filename = basename($this->localfile);
$this->modified = filemtime($this->localfile);
$jpegMeta = new \JpegMeta($this->localfile);
$this->title = $jpegMeta->getField('Simple.Title');
$this->description = $jpegMeta->getField('Iptc.Caption');
$this->created = $jpegMeta->getField('Date.EarliestTime');
$this->width = $jpegMeta->getField('File.Width');
$this->height = $jpegMeta->getField('File.Height');
}
if (preg_match(self::IMG_REGEX, $this->filename, $match))
$this->imagetype = $match[1];
}
public function isExternal()
{
return $this->isExternal;
}
public function getSrc()
{
return $this->src;
}
public function getFilename()
{
return $this->filename;
}
public function setFilename(string $filename)
{
$this->filename = $filename;
}
public function getLocalfile()
{
return $this->localfile;
}
public function setLocalfile(string $localfile)
{
$this->localfile = $localfile;
}
/**
* @return string
*/
public function getTitle()
{
if (empty($this->title) || $this->title == $this->filename) {
$title = str_replace('_', ' ', $this->filename);
$title = preg_replace(self::IMG_REGEX, '', $title);
$title = PhpString::ucwords($title);
return $title;
}
return $this->title;
}
/**
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* @return string
*/
public function getDescription()
{
return trim(str_replace("\n", ' ', $this->description));
}
/**
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return int
*/
public function getWidth()
{
return $this->width;
}
/**
* @param int $width
*/
public function setWidth($width)
{
$this->width = $width;
}
/**
* @return int
*/
public function getHeight()
{
return $this->height;
}
/**
* @param int $height
*/
public function setHeight($height)
{
$this->height = $height;
}
/**
* @return int
*/
public function getCreated()
{
return $this->created;
}
/**
* @param int $created
*/
public function setCreated($created)
{
$this->created = $created;
}
/**
* @return int
*/
public function getModified()
{
return $this->modified;
}
/**
* @param int $modified
*/
public function setModified($modified)
{
$this->modified = $modified;
}
public function getDetaillink()
{
return $this->detaillink;
}
public function setDetaillink($detaillink)
{
$this->detaillink = $detaillink;
}
}