-
Notifications
You must be signed in to change notification settings - Fork 50
/
ImageHandler.php
61 lines (50 loc) · 1.34 KB
/
ImageHandler.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
<?php
namespace Gregwar\ImageBundle;
use Gregwar\Image\Image;
/**
* Image manipulation class.
*
* @author Gregwar <[email protected]>
*/
class ImageHandler extends Image
{
protected $fileCallback = null;
/**
* @param null $originalFile
* @param null $width
* @param null $height
* @param bool $throwException
*/
public function __construct($originalFile = null, $width = null, $height = null, $throwException = null, $fallbackImage = null)
{
parent::__construct($originalFile, $width, $height);
$this->useFallback(!$throwException);
$this->setFallback($fallbackImage);
}
/**
* Defines the callback to call to compute the new filename.
*/
public function setFileCallback($fileCallback)
{
$this->fileCallback = $fileCallback;
}
/**
* When processing the filename, call the callback.
*/
protected function getFilename($filename)
{
$callback = $this->fileCallback;
if (null === $callback || substr($filename, 0, 1) == '/') {
return $filename;
}
return $callback($filename);
}
public function save($file, $type = 'guess', $quality = 80)
{
return parent::save($file, $type, $quality);
}
public function __toString()
{
return parent::__toString();
}
}