-
Notifications
You must be signed in to change notification settings - Fork 1
/
imthumb-meta.class.php
58 lines (50 loc) · 1.37 KB
/
imthumb-meta.class.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
<?php
/**
* A metadata container class to pass between ImThumb instances and ImThumbSource implementations
*/
class ImThumbMeta
{
public $src; // must be a fully resolvable URI
public $valid = true;
public $mtime;
public $fileSize;
public $mimeType = '';
public function __construct($src = null, $mtime = null, $fileSize = null, $mimeType = '')
{
$this->src = $src;
$this->mtime = $mtime;
$this->fileSize = $fileSize;
$this->mimeType = $mimeType;
if (!$src) {
$this->valid = false;
}
}
public function validateWith(ImThumb $generator)
{
if (!$this->valid) {
throw new ImThumbNotFoundException("Could not read image metadata", ImThumb::ERR_SRC_IMAGE);
}
if ($this->fileSize > $generator->param('maxSize')) {
throw new ImThumbException("Image file exceeds maximum processable size", ImThumb::ERR_SRC_IMAGE);
}
}
public function assignMimeType(Imagick $target)
{
if ($this->mimeType == 'image/jpeg') {
$target->setImageFormat('jpg');
} else if ($this->mimeType == 'image/gif') {
$target->setImageFormat('gif');
} else if ($this->mimeType == 'image/png') {
$target->setImageFormat('png');
}
}
// Helper for invaliding metadata when being read by Source classes. Just return this method call.
public function invalid()
{
$this->valid = false;
$this->mtime = 0;
$this->fileSize = 0;
$this->mimeType = '';
return $this;
}
}