Search code examples
phpgdmime-types

php gd imagecreatefromstring() and image mime type


is there a way to use imagecreatefromstring() and get somehow what is the image type?


Solution

  • When you use imagecreatefrom... methods, the image is loaded into memory as the uncompressed bitmap. there is not really a image type at this point. you can save it back out as whatever type you wish using the image... function.

    $img = imagecreatefromstring($data);
    
    imagepng($img, "file path and name");
    
    imagedestroy($img);
    

    https://www.php.net/manual/en/function.imagecreatefromstring.php