docker-php-extension-installer/scripts/tests/gd.php

72 lines
1.8 KiB
PHP
Raw Normal View History

2019-12-27 10:28:50 +00:00
<?php
$imageWidth = 8;
$imageHeight = 16;
$image = imagecreatetruecolor($imageWidth, $imageHeight);
2019-12-27 13:56:03 +00:00
$formats = [
2019-12-27 10:28:50 +00:00
'gd2',
'gif',
'jpeg',
'png',
'wbmp',
'webp',
'wbmp',
'xbm',
'xpm',
'gd',
2019-12-27 13:56:03 +00:00
];
2019-12-27 10:28:50 +00:00
if (PHP_VERSION_ID >= 70200) {
2019-12-27 13:56:03 +00:00
$formats = array_merge($formats, [
2019-12-27 10:28:50 +00:00
'bmp',
2019-12-27 13:56:03 +00:00
]);
2019-12-27 10:28:50 +00:00
}
$tempFile = null;
$image2 = null;
2019-12-27 13:56:03 +00:00
2019-12-27 10:28:50 +00:00
try {
foreach ($formats as $format) {
2019-12-27 13:56:03 +00:00
$loadFuntion = "imagecreatefrom{$format}";
2019-12-27 10:28:50 +00:00
if (!function_exists($loadFuntion)) {
2019-12-27 13:56:03 +00:00
throw new Exception("{$loadFuntion}() function is missing");
2019-12-27 10:28:50 +00:00
}
if ($format === 'xpm') {
continue;
}
2019-12-27 13:56:03 +00:00
$saveFuntion = "image{$format}";
2019-12-27 10:28:50 +00:00
if (!function_exists($saveFuntion)) {
2019-12-27 13:56:03 +00:00
throw new Exception("{$saveFuntion}() function is missing");
2019-12-27 10:28:50 +00:00
}
$tempFile = tempnam(sys_get_temp_dir(), 'dpei');
if ($saveFuntion($image, $tempFile) === false) {
2019-12-27 13:56:03 +00:00
throw new Exception("{$saveFuntion}() failed");
2019-12-27 10:28:50 +00:00
}
if (!is_file($tempFile) || filesize($tempFile) < 1) {
2019-12-27 13:56:03 +00:00
throw new Exception("{$saveFuntion}() created an empty file");
2019-12-27 10:28:50 +00:00
}
$image2 = $loadFuntion($tempFile);
unlink($tempFile);
$tempFile = null;
if (!is_resource($image2) || imagesx($image2) !== $imageWidth || imagesy($image2) !== $imageHeight) {
2019-12-27 13:56:03 +00:00
throw new Exception("{$loadFuntion}() failed");
2019-12-27 10:28:50 +00:00
}
imagedestroy($image2);
}
} finally {
imagedestroy($image);
if (is_resource($image2)) {
imagedestroy($image2);
}
2019-12-27 13:56:03 +00:00
if ($tempFile !== null) {
2019-12-27 10:28:50 +00:00
unlink($tempFile);
}
}
if (!function_exists('imagefttext')) {
2019-12-27 13:56:03 +00:00
throw new Exception('imagefttext() function is missing');
2019-12-27 10:28:50 +00:00
}
if (!function_exists('imageantialias')) {
2019-12-27 13:56:03 +00:00
throw new Exception('imageantialias() function is missing');
2019-12-27 10:28:50 +00:00
}
2019-12-27 13:56:03 +00:00
2019-12-27 10:28:50 +00:00
return true;