xref: /PHP-8.1/ext/gd/tests/imagefttext.phpt (revision a375d547)
1--TEST--
2imagefttext() function test
3--EXTENSIONS--
4gd
5--SKIPIF--
6<?php
7    if (!function_exists("imagefttext")) {
8        die("skip imagefttext() not available.");
9    }
10?>
11--FILE--
12<?php
13    $cwd = __DIR__;
14    $fontfile_8859 = "$cwd/test8859.ttf";
15
16    function testrun($im, $fontfile) {
17        $sx = imagesx($im);
18        $sy = imagesy($im);
19
20        $colour_w = imagecolorallocate($im, 255, 255, 255);
21        $colour_b = imagecolorallocate($im, 0, 0, 0);
22
23        imagefilledrectangle($im, 0, 0, $sx - 1, $sy - 1, $colour_b);
24        imagefttext($im, $sy * 0.75, 0, 0, $sy - 1, $colour_w, $fontfile, "A", array());
25
26        $cnt = 0;
27        for ($y = 0; $y < $sy; ++$y) {
28            for ($x = 0; $x < $sx; ++$x) {
29                if (imagecolorat($im, $x, $y) == $colour_b) {
30                    ++$cnt;
31                }
32            }
33        }
34
35        // imagecolordeallocate($im, $colour_w);
36        // imagecolordeallocate($im, $colour_b);
37
38        return ($cnt < ($sx * $sy));
39    }
40
41    $im = imagecreate(256, 256);
42    var_dump(testrun($im, $fontfile_8859));
43    imagedestroy($im);
44
45    $im = imagecreatetruecolor(256, 256);
46    var_dump(testrun($im, $fontfile_8859));
47    imagedestroy($im);
48?>
49--EXPECT--
50bool(true)
51bool(true)
52