Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
GetImageSize | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
1 / 1 |
doDetect | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 |
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 | * Returns: |
12 | * - mime type (string) (if it is in fact an image, and type could be determined) |
13 | * - false (if it is not an image type that the server knowns about) |
14 | * - null (if nothing can be determined) |
15 | * |
16 | * @param string $filePath The path to the file |
17 | * @return string|false|null mimetype (if it is an image, and type could be determined), |
18 | * false (if it is not an image type that the server knowns about) |
19 | * or null (if nothing can be determined) |
20 | */ |
21 | protected function doDetect($filePath) |
22 | { |
23 | // getimagesize is slower than exif_imagetype |
24 | // It may not return "mime". In that case we can rely on that the file is not an image (and return false) |
25 | if (function_exists('getimagesize')) { |
26 | try { |
27 | $imageSize = getimagesize($filePath); |
28 | return (isset($imageSize['mime']) ? $imageSize['mime'] : false); |
29 | } catch (\Exception $e) { |
30 | // well well, don't let this stop us either |
31 | return null; |
32 | } |
33 | } |
34 | return null; |
35 | } |
36 | } |