1 | <?php |
||
2 | |||
3 | namespace ImageMimeTypeGuesser\Detectors; |
||
4 | |||
5 | class GetImageSize extends AbstractDetector |
||
6 | { |
||
7 | |||
8 | /** |
||
9 | * Try to detect mime type of image using "getimagesize" |
||
10 | * |
||
11 | * Like all detectors, it returns: |
||
12 | * - null (if it cannot be determined) |
||
13 | * - false (if it can be determined that this is not an image) |
||
14 | * - mime (if it is in fact an image, and type could be determined) |
||
15 | * @return mime | null | false. |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
16 | */ |
||
17 | protected function doDetect($filePath) |
||
18 | { |
||
19 | // getimagesize is slower than exif_imagetype |
||
20 | // It may not return "mime". In that case we can rely on that the file is not an image (and return false) |
||
21 | if (function_exists('getimagesize')) { |
||
22 | try { |
||
23 | $imageSize = getimagesize($filePath); |
||
24 | return (isset($imageSize['mime']) ? $imageSize['mime'] : false); |
||
25 | } catch (\Exception $e) { |
||
26 | // well well, don't let this stop us either |
||
27 | } |
||
28 | } |
||
29 | } |
||
30 | } |
||
31 |