From 6b47bfadbe129619f9afc653be4b654cda4214f8 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Fri, 27 Dec 2019 11:28:50 +0100 Subject: [PATCH] Add GD-specific tests Test: gd --- scripts/tests/gd.php | 69 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 scripts/tests/gd.php diff --git a/scripts/tests/gd.php b/scripts/tests/gd.php new file mode 100644 index 0000000..8552006 --- /dev/null +++ b/scripts/tests/gd.php @@ -0,0 +1,69 @@ += 70200) { + $formats = array_merge($formats, array( + 'bmp', + )); +} +$tempFile = null; +$image2 = null; +try { + foreach ($formats as $format) { + $loadFuntion = "imagecreatefrom${format}"; + if (!function_exists($loadFuntion)) { + throw new Exception("$loadFuntion() function is missing"); + } + if ($format === 'xpm') { + continue; + } + $saveFuntion = "image${format}"; + if (!function_exists($saveFuntion)) { + throw new Exception("$saveFuntion() function is missing"); + } + $tempFile = tempnam(sys_get_temp_dir(), 'dpei'); + 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"); + } + $image2 = $loadFuntion($tempFile); + unlink($tempFile); + $tempFile = null; + if (!is_resource($image2) || imagesx($image2) !== $imageWidth || imagesy($image2) !== $imageHeight) { + throw new Exception("$loadFuntion() failed"); + } + imagedestroy($image2); + } +} finally { + imagedestroy($image); + if (is_resource($image2)) { + imagedestroy($image2); + } + if($tempFile !== null) { + unlink($tempFile); + } +} + +if (!function_exists('imagefttext')) { + throw new Exception("imagefttext() function is missing"); +} +if (!function_exists('imageantialias')) { + throw new Exception("imageantialias() function is missing"); +} +return true;