From 4005bb69cbe256ed5a6151a8d44fbd4190bd6cc5 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Fri, 31 Jan 2020 15:59:34 +0100 Subject: [PATCH] Workaround for https://bugs.php.net/bug.php?id=66339 for imagexbm on PHP 5.5 --- scripts/tests/gd.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/tests/gd.php b/scripts/tests/gd.php index 4f73b15..f7b562b 100644 --- a/scripts/tests/gd.php +++ b/scripts/tests/gd.php @@ -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);