xref: /php-src/ext/gd/tests/bug50194.phpt (revision 0b8466f2)
1--TEST--
2Bug #50194 (imagettftext broken on transparent background w/o alphablending)
3--EXTENSIONS--
4gd
5--SKIPIF--
6<?php
7if (!function_exists('imagettftext')) die('skip imagettftext() not available');
8if (!(imagetypes() & IMG_PNG)) {
9    die("skip No PNG support");
10}
11?>
12--FILE--
13<?php
14require_once __DIR__ . DIRECTORY_SEPARATOR . 'func.inc';
15
16$im = imagecreatetruecolor(240, 55);
17$background = imagecolorallocatealpha($im, 60, 60, 60, 0); // no tranparency
18$black = imagecolorallocate($im, 0, 0, 0);
19imagealphablending($im, false);
20imagefilledrectangle($im, 0, 0, 239, 54, $background);
21$text = 'Testing ... ';
22$font = __DIR__ . DIRECTORY_SEPARATOR . 'Tuffy.ttf';
23imagettftext($im, 40, 0, 10, 40, $black, $font, $text);
24imagesavealpha($im, true);
25
26ob_start();
27test_image_equals_file(__DIR__ . DIRECTORY_SEPARATOR . 'bug50194.png', $im);
28$output = ob_get_clean();
29assert(preg_match('/The images are equal|The images differ in (\d+) pixels/', $output, $matches));
30if (isset($matches[1]) && $matches[1] > 2000) {
31    echo "The images differ in {$matches[1]} pixels.\n";
32} else {
33    echo "The images are similar.\n";
34}
35
36imagedestroy($im);
37?>
38--EXPECT--
39The images are similar.
40