|
4 | 4 |
|
5 | 5 | use Safe\Exceptions\ImageException;
|
6 | 6 |
|
| 7 | +/** |
| 8 | + * The getimagesize function will determine the |
| 9 | + * size of any supported given image file and return the dimensions along with |
| 10 | + * the file type and a height/width text string to be used inside a |
| 11 | + * normal HTML IMG tag and the |
| 12 | + * correspondent HTTP content type. |
| 13 | + * |
| 14 | + * getimagesize can also return some more information |
| 15 | + * in imageinfo parameter. |
| 16 | + * |
| 17 | + * @param string $filename This parameter specifies the file you wish to retrieve information |
| 18 | + * about. It can reference a local file or (configuration permitting) a |
| 19 | + * remote file using one of the supported streams. |
| 20 | + * @param array $imageinfo This optional parameter allows you to extract some extended |
| 21 | + * information from the image file. Currently, this will return the |
| 22 | + * different JPG APP markers as an associative array. |
| 23 | + * Some programs use these APP markers to embed text information in |
| 24 | + * images. A very common one is to embed |
| 25 | + * IPTC information in the APP13 marker. |
| 26 | + * You can use the iptcparse function to parse the |
| 27 | + * binary APP13 marker into something readable. |
| 28 | + * |
| 29 | + * The imageinfo only supports |
| 30 | + * JFIF files. |
| 31 | + * @return array Returns an array with up to 7 elements. Not all image types will include |
| 32 | + * the channels and bits elements. |
| 33 | + * |
| 34 | + * Index 0 and 1 contains respectively the width and the height of the image. |
| 35 | + * |
| 36 | + * Index 2 is one of the IMAGETYPE_XXX constants indicating |
| 37 | + * the type of the image. |
| 38 | + * |
| 39 | + * Index 3 is a text string with the correct |
| 40 | + * height="yyy" width="xxx" string that can be used |
| 41 | + * directly in an IMG tag. |
| 42 | + * |
| 43 | + * mime is the correspondant MIME type of the image. |
| 44 | + * This information can be used to deliver images with the correct HTTP |
| 45 | + * Content-type header: |
| 46 | + * |
| 47 | + * getimagesize and MIME types |
| 48 | + * |
| 49 | + * |
| 50 | + * ]]> |
| 51 | + * |
| 52 | + * |
| 53 | + * |
| 54 | + * channels will be 3 for RGB pictures and 4 for CMYK |
| 55 | + * pictures. |
| 56 | + * |
| 57 | + * bits is the number of bits for each color. |
| 58 | + * |
| 59 | + * For some image types, the presence of channels and |
| 60 | + * bits values can be a bit |
| 61 | + * confusing. As an example, GIF always uses 3 channels |
| 62 | + * per pixel, but the number of bits per pixel cannot be calculated for an |
| 63 | + * animated GIF with a global color table. |
| 64 | + * |
| 65 | + * On failure, FALSE is returned. |
| 66 | + * @throws ImageException |
| 67 | + * |
| 68 | + */ |
| 69 | +function getimagesize(string $filename, array &$imageinfo = null): array |
| 70 | +{ |
| 71 | + error_clear_last(); |
| 72 | + $result = \getimagesize($filename, $imageinfo); |
| 73 | + if ($result === false) { |
| 74 | + throw ImageException::createFromPhpError(); |
| 75 | + } |
| 76 | + return $result; |
| 77 | +} |
| 78 | + |
| 79 | + |
7 | 80 | /**
|
8 | 81 | * image2wbmp outputs or save a WBMP
|
9 | 82 | * version of the given image.
|
|
0 commit comments