xref: /PHP-8.2/ext/gd/tests/bug50194.phpt (revision a375d547)
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');
8//die('skip freetype issues');
9?>
10--FILE--
11<?php
12require_once __DIR__ . DIRECTORY_SEPARATOR . 'func.inc';
13
14$im = imagecreatetruecolor(240, 55);
15$background = imagecolorallocatealpha($im, 60, 60, 60, 0); // no tranparency
16$black = imagecolorallocate($im, 0, 0, 0);
17imagealphablending($im, false);
18imagefilledrectangle($im, 0, 0, 239, 54, $background);
19$text = 'Testing ... ';
20$font = __DIR__ . DIRECTORY_SEPARATOR . 'Tuffy.ttf';
21imagettftext($im, 40, 0, 10, 40, $black, $font, $text);
22imagesavealpha($im, true);
23
24ob_start();
25test_image_equals_file(__DIR__ . DIRECTORY_SEPARATOR . 'bug50194.png', $im);
26$output = ob_get_clean();
27assert(preg_match('/The images are equal|The images differ in (\d+) pixels/', $output, $matches));
28if (isset($matches[1]) && $matches[1] > 2000) {
29    echo "The images differ in {$matches[1]} pixels.\n";
30} else {
31    echo "The images are similar.\n";
32}
33
34imagedestroy($im);
35?>
36--EXPECT--
37The images are similar.
38