imagefttext.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. --TEST--
  2. imagefttext() function test
  3. --EXTENSIONS--
  4. gd
  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. function testrun($im, $fontfile) {
  16. $sx = imagesx($im);
  17. $sy = imagesy($im);
  18. $colour_w = imagecolorallocate($im, 255, 255, 255);
  19. $colour_b = imagecolorallocate($im, 0, 0, 0);
  20. imagefilledrectangle($im, 0, 0, $sx - 1, $sy - 1, $colour_b);
  21. imagefttext($im, $sy * 0.75, 0, 0, $sy - 1, $colour_w, $fontfile, "A", array());
  22. $cnt = 0;
  23. for ($y = 0; $y < $sy; ++$y) {
  24. for ($x = 0; $x < $sx; ++$x) {
  25. if (imagecolorat($im, $x, $y) == $colour_b) {
  26. ++$cnt;
  27. }
  28. }
  29. }
  30. // imagecolordeallocate($im, $colour_w);
  31. // imagecolordeallocate($im, $colour_b);
  32. return ($cnt < ($sx * $sy));
  33. }
  34. $im = imagecreate(256, 256);
  35. var_dump(testrun($im, $fontfile_8859));
  36. imagedestroy($im);
  37. $im = imagecreatetruecolor(256, 256);
  38. var_dump(testrun($im, $fontfile_8859));
  39. imagedestroy($im);
  40. ?>
  41. --EXPECT--
  42. bool(true)
  43. bool(true)