-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathFilePathImageDecoder.php
39 lines (31 loc) · 1.09 KB
/
FilePathImageDecoder.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
<?php
namespace Intervention\Image\Drivers\Imagick\Decoders;
use Exception;
use Intervention\Image\Exceptions\DecoderException;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageInterface;
class FilePathImageDecoder extends BinaryImageDecoder implements DecoderInterface
{
public function decode(mixed $input): ImageInterface|ColorInterface
{
if (!is_string($input)) {
throw new DecoderException('Unable to decode input');
}
if (strlen($input) > PHP_MAXPATHLEN) {
throw new DecoderException('Unable to decode input');
}
try {
if (!@is_file($input)) {
throw new DecoderException('Unable to decode input');
}
} catch (Exception) {
throw new DecoderException('Unable to decode input');
}
// decode image
$image = parent::decode(file_get_contents($input));
// set file path on origin
$image->origin()->setFilePath($input);
return $image;
}
}