April 16, 2012
PHP detect if ImageCreateFromString fail
Question by Jerome Ansia
I would like to be able to detect when i launch this function if it’s fail or not due to the memory size limit
ImageCreateFromString();
Answer by rauchmelder
In the PHP-Manual which you’ve linked there is the solution already written:
Return Values
An image resource will be returned on success. FALSE is returned if the image type is unsupported, the data is not in a recognised format, or the image is corrupt and cannot be loaded.
Answer by Starx
If you had read the manual you linked in your question, there is an answer already.
An image resource will be returned on success. FALSE is returned if the image type is unsupported, the data is not in a recognised format, or the image is corrupt and cannot be loaded.
There is an example for that
$im = imagecreatefromstring($data);
if ($im !== false) {
// OK
}
else {
echo 'An error occurred.';
}