Workaround for https://bugs.php.net/bug.php?id=66339 for imagexbm on PHP 5.5

pull/102/head
Michele Locati 2020-01-31 15:59:34 +01:00
parent ea96de853e
commit 4005bb69cb
No known key found for this signature in database
GPG Key ID: 98B7CE2E7234E28B
1 changed files with 11 additions and 2 deletions

View File

@ -37,11 +37,20 @@ try {
throw new Exception("{$saveFuntion}() function is missing");
}
$tempFile = tempnam(sys_get_temp_dir(), 'dpei');
ob_start();
if ($saveFuntion($image, $tempFile) === false) {
throw new Exception("{$saveFuntion}() failed");
}
if (!is_file($tempFile) || filesize($tempFile) < 1) {
throw new Exception("{$saveFuntion}() created an empty file");
$contents = ob_get_contents();
ob_end_clean();
if (!is_file($tempFile)) {
throw new Exception("{$saveFuntion}() didn't create a file");
}
if (filesize($tempFile) < 1) {
if ($format !== 'xbm' || PHP_VERSION_ID >= 50600 || $contents === '') {
throw new Exception("{$saveFuntion}() created an empty file");
}
file_put_contents($tempFile, $contents);
}
$image2 = $loadFuntion($tempFile);
unlink($tempFile);