Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ tests/*/*/*.sh
*/tests/*/*/*.sh
*/*/tests/*.diff
*/*/tests/*.out
*/*/tests/*.out.png
*/*/tests/*.php
*/*/tests/*.exp
*/*/tests/*.log
Expand Down
9 changes: 3 additions & 6 deletions ext/gd/tests/bug22544.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ Bug #22544 (TrueColor transparency in PNG images).
?>
--FILE--
<?php
$dest = dirname(realpath(__FILE__)) . '/bug22544.png';
@unlink($dest);
$image = imageCreateTruecolor(640, 100);
$transparent = imageColorAllocate($image, 0, 0, 0);
$red = imageColorAllocate($image, 255, 50, 50);
imageColorTransparent($image, $transparent);
imageFilledRectangle($image, 0, 0, 640-1, 100-1, $transparent);
imagePng($image, $dest);
echo md5_file($dest) . "\n";
@unlink($dest);
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/bug22544.png', $image);
?>
--EXPECT--
10a57d09a2c63fad87b85b38d6b258d6
The images are equal.
Binary file added ext/gd/tests/bug22544.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions ext/gd/tests/func.inc
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,71 @@ function get_libxpm_version()
return $version;
}

/**
* Tests that an in-memory image equals a PNG file.
*
* It checks for equal image sizes, and whether any pixels are different.
* The textual result is printed, so the EXPECT section should contain the line
* "The images are equal."
*
* If the PNG file does not exists, or the images are not equal, a diagnostic
* message is printed, and the actual file is stored right beside the temporary
* .php test file with the extension .out.png, to be able to manually inspect
* the result.
*
* @param string $filename
* @param resource $actual
* @return void
*/
function test_image_equals_file($filename, $actual)
{
if (!file_exists($filename)) {
echo "The expected image does not exist.\n";
save_actual_image($actual);
return;
}
$expected = imagecreatefrompng($filename);
$exp_x = imagesx($expected);
$exp_y = imagesy($expected);
$act_x = imagesx($actual);
$act_y = imagesy($actual);
if ($exp_x != $act_x || $exp_y != $act_y) {
echo "The image size differs: expected {$exp_x}x{$exp_y}, got {$act_x}x{$act_y}.\n";
save_actual_image($actual);
imagedestroy($expected);
return;
}
$pixels_changed = 0;
for ($y = 0; $y < $exp_y; $y++) {
for ($x = 0; $x < $exp_x; $x ++) {
$exp_c = imagecolorat($expected, $x, $y);
$act_c = imagecolorat($actual, $x, $y);
if ($exp_c != $act_c) {
$pixels_changed++;
}
}
}
if (!$pixels_changed) {
echo "The images are equal.\n";
} else {
echo "The images differ in {$pixels_changed} pixels.\n";
save_actual_image($actual);
}
imagedestroy($expected);
}

/**
* Saves an actual image to disk.
*
* The image is saved right beside the temporary .php test file with the
* extension .out.png.
*
* @param resource $image
* @return void
*/
function save_actual_image($image)
{
$pathinfo = pathinfo($_SERVER['SCRIPT_FILENAME']);
$filename = "{$pathinfo['dirname']}/{$pathinfo['filename']}.out.png";
imagepng($image, $filename);
}
10 changes: 3 additions & 7 deletions ext/gd/tests/imagearc_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc with white color
imagearc($image, 50, 50, 30, 30, 0, 180, $white);

ob_start();
imagepng($image);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagearc_basic.png', $image);
?>
--EXPECT--
f18ad8001afefee2e9b8c08d6884425b
The images are equal.
Binary file added ext/gd/tests/imagearc_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagearc_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc with white color
imagearc($image, 50, 50, 30, 30, 0, 180);

ob_start();
imagepng($image);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagearc_error1.png', $image);
?>
--EXPECTF--
Warning: imagearc() expects exactly 8 parameters, 7 given in %s on line %d
abebb25b5a2813cfbf92f1f24365786a
The images are equal.
Binary file added ext/gd/tests/imagearc_error1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagearc_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc with white color
imagearc($image, 50, 50, 30, 30, 0, -90, $white);

ob_start();
imagepng($image);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagearc_variation1.png', $image);
?>
--EXPECT--
ed2c8427a9922dfd8a105f10a88a0d20
The images are equal.
Binary file added ext/gd/tests/imagearc_variation1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagearc_variation2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc with white color
imagearc($image, 50, 50, 30, 30, -90, 0, $white);

ob_start();
imagepng($image);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagearc_variation2.png', $image);
?>
--EXPECT--
463b4aea9d9acfab30016ee92613c779
The images are equal.
Binary file added ext/gd/tests/imagearc_variation2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagechar_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ $white = imagecolorallocate($image, 255,255,255);

$result = imagechar($image, 1, 5, 5, 'C', $white);

ob_start();
imagepng($image, null, 9);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagechar_basic.png', $image);
?>
--EXPECT--
e94962ac28ad03bd4142cb1abe9ef98b
The images are equal.
Binary file added ext/gd/tests/imagechar_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagecharup_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ $white = imagecolorallocate($image, 255,255,255);

$result = imagecharup($image, 1, 5, 5, 'C', $white);

ob_start();
imagepng($image, null, 9);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagecharup_basic.png', $image);
?>
--EXPECT--
79b48d5cef6d489bb68573df0296d775
The images are equal.
Binary file added ext/gd/tests/imagecharup_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagecolorallocatealpha_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ $corA = imagecolorallocatealpha($img, 50, 100, 255, 50);
$half = imagefilledarc ( $img, 75, 75, 70, 70, 0, 180, $cor, IMG_ARC_PIE );
$half2 = imagefilledarc ( $img, 75, 75, 70, 70, 180, 360, $corA, IMG_ARC_PIE );

ob_start();
imagepng($img, null, 9);
$imgsrc = ob_get_contents();
ob_end_clean();

var_dump(md5(base64_encode($imgsrc)));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagecolorallocatealpha_basic.png', $img);
var_dump($corA);
?>
--EXPECT--
string(32) "b856a0b1a15efe0f79551ebbb5651fe8"
The images are equal.
int(842163455)
Binary file added ext/gd/tests/imagecolorallocatealpha_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagecolorset_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ $bg = imagecolorat($im, 0, 0);
// Set the backgrund to be blue
imagecolorset($im, $bg, 0, 0, 255);

// Get output and generate md5 hash
ob_start();
imagepng($im, null, 9);
$result_image = ob_get_contents();
ob_end_clean();
echo md5(base64_encode($result_image));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagecolorset_basic.png', $im);
imagedestroy($im);
?>
--EXPECT--
6f2002aafb57b2d275fad6a6258d7476
The images are equal.
Binary file added ext/gd/tests/imagecolorset_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imageconvolution_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ $gaussian = array(

imageconvolution($image, $gaussian, 16, 0);

ob_start();
imagepng($image, null, 9);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imageconvolution_basic.png', $image);
?>
--EXPECT--
594576a2a2a689447ffc07eb5a73f09b
The images are equal.
Binary file added ext/gd/tests/imageconvolution_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagecreatetruecolor_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ Rafael Dohms <rdohms [at] gmail [dot] com>
<?php
$image = imagecreatetruecolor(180, 30);

ob_start();
imagepng($image, null, 9);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagecreatetruecolor_basic.png', $image);
?>
--EXPECT--
5a8fe9864cbd20e5dbe730c77f30db95
The images are equal.
Binary file added ext/gd/tests/imagecreatetruecolor_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imageellipse_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ $image = imagecreatetruecolor(400, 300);
// Draw a white ellipse
imageellipse($image, 200, 150, 300, 200, 16777215);

ob_start();
imagepng($image, null, 9);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imageellipse_basic.png', $image);
?>
--EXPECT--
d8b9bc2ca224bd68569413f4617f8e1f
The images are equal.
Binary file added ext/gd/tests/imageellipse_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagefilledarc_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc and fill it with white color
imagefilledarc($image, 50, 50, 30, 30, 0, 90, $white, IMG_ARC_PIE);

ob_start();
imagepng($image);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagefilledarc_basic.png', $image);
?>
--EXPECT--
894f394c7f2e2364642ef27fea6bfc33
The images are equal.
Binary file added ext/gd/tests/imagefilledarc_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagefilledarc_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc and fill it with white color
imagefilledarc($image, 50, 50, 30, 30, 0, 90, $white);

ob_start();
imagepng($image);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagefilledarc_error1.png', $image);
?>
--EXPECTF--
Warning: imagefilledarc() expects exactly 9 parameters, 8 given in %s on line %d
abebb25b5a2813cfbf92f1f24365786a
The images are equal.
Binary file added ext/gd/tests/imagefilledarc_error1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagefilledarc_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc and fill it with white color
imagefilledarc($image, 50, 50, 30, 30, 0, -25, $white, IMG_ARC_PIE);

ob_start();
imagepng($image);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagefilledarc_variation1.png', $image);
?>
--EXPECT--
b77bbb8207e5adbebfcc8bd1c4074305
The images are equal.
Binary file added ext/gd/tests/imagefilledarc_variation1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagefilledarc_variation2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an arc and fill it with white color
imagefilledarc($image, 50, 50, 30, 30, -25, 25, $white, IMG_ARC_PIE);

ob_start();
imagepng($image);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagefilledarc_variation2.png', $image);
?>
--EXPECT--
b8b572812b3c85678f6c38c4ecca7619
The images are equal.
Binary file added ext/gd/tests/imagefilledarc_variation2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagefilledellipse_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ $white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
//create an ellipse and fill it with white color
imagefilledellipse($image, 50, 50, 40, 30, $white);

ob_start();
imagepng($image);
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagefilledellipse_basic.png', $image);
?>
--EXPECT--
9ba540bba1b78c9f08efaa6fa0afd93b
The images are equal.
Binary file added ext/gd/tests/imagefilledellipse_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions ext/gd/tests/imagefilltoborder_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ imageellipse( $image, 50, 50, 50, 50, imagecolorallocate( $image, 0, 0, 0 ) );
// Fill border
imagefilltoborder( $image, 50, 50, imagecolorallocate( $image, 0, 0, 0 ), imagecolorallocate( $image, 255, 0, 0 ) );

ob_start();
imagepng( $image, null, 9 );
$img = ob_get_contents();
ob_end_clean();

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagefilltoborder_basic.png', $image);

?>
--EXPECT--
847ec236f1c4d14c465306c8408550fc
The images are equal.
Binary file added ext/gd/tests/imagefilltoborder_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 5 additions & 9 deletions ext/gd/tests/imagegammacorrect_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ $half = imagefilledarc ( $image, 75, 75, 70, 70, 0, 180, $grey, IMG_ARC_PIE );
$half2 = imagefilledarc ( $image, 75, 75, 70, 70, 0, -180, $gray, IMG_ARC_PIE );

$gamma = imagegammacorrect($image, 1, 5);
var_dump((bool) $gamma);

if ($gamma){
ob_start();
imagepng($image, null, 9);
$img = ob_get_contents();
ob_end_clean();
}

echo md5(base64_encode($img));
include_once __DIR__ . '/func.inc';
test_image_equals_file(__DIR__ . '/imagegammacorrect_basic.png', $image);
?>
--EXPECT--
30639772903913594bc665743e1b9ab8
bool(true)
The images are equal.
Binary file added ext/gd/tests/imagegammacorrect_basic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading