copyresized.phpt 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. --TEST--
  2. imagecopyresized
  3. --EXTENSIONS--
  4. gd
  5. --FILE--
  6. <?php
  7. function get_hexcolor($im, $c) {
  8. if (imageistruecolor($im)) {
  9. return $c;
  10. }
  11. $colors = imagecolorsforindex($im, $c);
  12. return ($colors['red'] << 16) + ($colors['green'] << 8) + ($colors['blue']);
  13. }
  14. function check_doublesize($dst) {
  15. $im = imagecreatetruecolor(38,38);
  16. imagefill($im,0,0, 0xffffff);
  17. imagefilledrectangle($im, 0,0,9,9, 0xff0000);
  18. imagefilledrectangle($im, 0,28,9,37, 0xff0000);
  19. imagefilledrectangle($im, 28,0,37,9, 0xff0000);
  20. imagefilledrectangle($im, 28,28,37,37, 0xff0000);
  21. imagefilledrectangle($im, 14,14,23,23, 0xff0000);
  22. for ($x = 0; $x < 38; $x++) {
  23. for ($y = 0; $y < 38; $y++) {
  24. $p1 = imagecolorat($im, $x, $y);
  25. $p2 = imagecolorat($dst, $x, $y);
  26. if (get_hexcolor($im, $p1) != get_hexcolor($dst, $p2)) {
  27. return false;
  28. }
  29. }
  30. }
  31. return true;
  32. }
  33. $src_tc = imagecreatetruecolor(19,19);
  34. imagefill($src_tc, 0,0, 0xffffff);
  35. imagefilledrectangle($src_tc, 0,0,4,4, 0xff0000);
  36. imagefilledrectangle($src_tc, 14,0,18,4, 0xff0000);
  37. imagefilledrectangle($src_tc, 0,14,4,18, 0xff0000);
  38. imagefilledrectangle($src_tc, 14,14,18,18, 0xff0000);
  39. imagefilledrectangle($src_tc, 7,7,11,11, 0xff0000);
  40. $dst_tc = imagecreatetruecolor(38,38);
  41. imagecopyresized($dst_tc, $src_tc, 0,0, 0,0, imagesx($dst_tc), imagesy($dst_tc), 19,19);
  42. if (!check_doublesize($dst_tc)) exit("1 failed\n");
  43. echo "TC->TC: ok\n";
  44. $src_tc = imagecreate(19,19);
  45. $white = imagecolorallocate($src_tc, 255,255,255);
  46. $red = imagecolorallocate($src_tc, 255,0,0);
  47. imagefilledrectangle($src_tc, 0,0,4,4, $red);
  48. imagefilledrectangle($src_tc, 14,0,18,4, $red);
  49. imagefilledrectangle($src_tc, 0,14,4,18, $red);
  50. imagefilledrectangle($src_tc, 14,14,18,18, $red);
  51. imagefilledrectangle($src_tc, 7,7,11,11, $red);
  52. $dst_tc = imagecreatetruecolor(38,38);
  53. imagecopyresized($dst_tc, $src_tc, 0,0, 0,0, imagesx($dst_tc), imagesy($dst_tc), 19,19);
  54. if (!check_doublesize($dst_tc)) exit("2 failed\n");
  55. echo "P->TC: ok\n";
  56. $src_tc = imagecreate(19,19);
  57. $white = imagecolorallocate($src_tc, 255,255,255);
  58. $red = imagecolorallocate($src_tc, 255,0,0);
  59. imagefilledrectangle($src_tc, 0,0,4,4, $red);
  60. imagefilledrectangle($src_tc, 14,0,18,4, $red);
  61. imagefilledrectangle($src_tc, 0,14,4,18, $red);
  62. imagefilledrectangle($src_tc, 14,14,18,18, $red);
  63. imagefilledrectangle($src_tc, 7,7,11,11, $red);
  64. $dst_tc = imagecreate(38,38);
  65. $white = imagecolorallocate($src_tc, 255,255,255);
  66. $red = imagecolorallocate($src_tc, 255,0,0);
  67. imagecopyresized($dst_tc, $src_tc, 0,0, 0,0, imagesx($dst_tc), imagesy($dst_tc), 19,19);
  68. if (!check_doublesize($dst_tc)) exit("3 failed\n");
  69. echo "P->P: ok\n";
  70. ?>
  71. --EXPECT--
  72. TC->TC: ok
  73. P->TC: ok
  74. P->P: ok