imagettftext_charmap_order.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. --TEST--
  2. Font charmap order is deterministic based on order in the font, use the selected encoding
  3. --SKIPIF--
  4. <?php
  5. if(!extension_loaded('gd')){ die('skip gd extension not available'); }
  6. if(!function_exists('imagettftext')) die('skip imagettftext() not available');
  7. if(gd_info()['JIS-mapped Japanese Font Support']) die('skip JIS-mapped Japanese Font Support not supported');
  8. ?>
  9. --FILE--
  10. <?php
  11. // this is an Apache Licensed font, see separate LICENSE file
  12. $font = __DIR__.'/Rochester-Regular.otf';
  13. // thank you Helgi
  14. $sample_string = "\xC3\x9E\xC3\xB6";
  15. $im = imagecreatetruecolor(
  16. 100,
  17. 80
  18. );
  19. $white = imagecolorallocate($im, 255, 255, 255);
  20. $black = imagecolorallocate($im, 0, 0, 0);
  21. imagefilledrectangle(
  22. $im,
  23. 0,
  24. 0,
  25. 100,
  26. 80,
  27. $white
  28. );
  29. imagettftext(
  30. $im,
  31. 45,
  32. 0,
  33. 15,
  34. 60,
  35. $black,
  36. $font,
  37. $sample_string
  38. );
  39. $w = imagesx($im);
  40. $h = imagesy($im);
  41. $black_pixels = 0;
  42. for ($y = 0; $y < $h; $y++) {
  43. for ($x = 0; $x < $w; $x++) {
  44. $rgb = imagecolorat($im, $x, $y);
  45. if ($rgb === 0) {
  46. ++$black_pixels;
  47. }
  48. }
  49. }
  50. if ($black_pixels >= 10) {
  51. printf("SUCCESS %d black pixels\n", $black_pixels);
  52. } else {
  53. printf("FAIL %d black pixels\n", $black_pixels);
  54. }
  55. imagedestroy($im);
  56. ?>
  57. --EXPECTF--
  58. SUCCESS %d black pixels