Add GD-specific tests

Test: gd
pull/94/head
Michele Locati 2019-12-27 11:28:50 +01:00
parent f98082b83c
commit 6b47bfadbe
No known key found for this signature in database
GPG Key ID: 98B7CE2E7234E28B
1 changed files with 69 additions and 0 deletions

69
scripts/tests/gd.php Normal file
View File

@ -0,0 +1,69 @@
<?php
$imageWidth = 8;
$imageHeight = 16;
$image = imagecreatetruecolor($imageWidth, $imageHeight);
$formats = array(
'gd2',
'gif',
'jpeg',
'png',
'wbmp',
'webp',
'wbmp',
'xbm',
'xpm',
'gd',
);
if (PHP_VERSION_ID >= 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;