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