Question

I have seen a code which confuses me a lot. The code is:

public static function CreateObject($url){
$url = "temp/".$url;
$imgInfo = getimagesize($url);
switch($imgInfo['mime']){
    case 'image/jpeg':
        $object = imagecreatefromjpeg($url);
        //print 'jpeg';
        break;
    case 'image/png':
        $object = imagecreatefrompng($url);
        //print 'png';
        break;
    case 'image/gif':
        $object = imagecreatefromgif($url);
        //print 'gif';
        break;
    default:
        return FALSE;
        break;

}
return $object;
}

Here I just need to know whether in $imageInfo['mime'] mime is a key or not. I haven’t seen $imageInfo declared as an array. And $imageInfo is declared as:

$url = "temp/".$url;
$imgInfo = getimagesize($url);

So I just need to know whether mime acts as a key or not.

Was it helpful?

Solution

mime is absolutely correct key for array returned by getimagesize() function.

According to the manual page:

Returns an array with up to 7 elements. Not all image types will include the channels and bits elements.

...

mime is the correspondant MIME type of the image.

So mime always exists in the result array. Answering your question literaly: yes, mime is an array key there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top