copy.phpt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. --TEST--
  2. imagecopy
  3. --EXTENSIONS--
  4. gd
  5. --FILE--
  6. <?php
  7. $src_tc = imagecreatetruecolor(5,5);
  8. imagefill($src_tc, 0,0, 0xffffff);
  9. imagesetpixel($src_tc, 3,3, 0xff0000);
  10. imagesetpixel($src_tc, 0,0, 0x0000ff);
  11. imagesetpixel($src_tc, 4,4, 0x00ff00);
  12. $dst_tc = imagecreatetruecolor(5,5);
  13. imagecopy($dst_tc, $src_tc, 0,0, 0,0, imagesx($src_tc), imagesy($src_tc));
  14. $p1 = imagecolorat($dst_tc, 3,3) == 0xff0000;
  15. $p2 = imagecolorat($dst_tc, 0,0) == 0x0000ff;
  16. $p3 = imagecolorat($dst_tc, 4,4) == 0x00ff00;
  17. if ($p1 && $p2 && $p3) {
  18. echo "TC/TC: ok\n";
  19. }
  20. imagedestroy($src_tc); imagedestroy($dst_tc);
  21. $src_tc = imagecreatetruecolor(5,5);
  22. imagefill($src_tc, 0,0, 0xffffff);
  23. imagesetpixel($src_tc, 3,3, 0xff0000);
  24. imagesetpixel($src_tc, 0,0, 0x0000ff);
  25. imagesetpixel($src_tc, 4,4, 0x00ff00);
  26. $dst_tc = imagecreate(5,5);
  27. imagecopy($dst_tc, $src_tc, 0,0, 0,0, imagesx($src_tc), imagesy($src_tc));
  28. $c1 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 3,3));
  29. $c2 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 0,0));
  30. $c3 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 4,4));
  31. $p1 = $c1['red'] == 0xff && $c1['blue']==0x00 && $c1['green']==0x00;
  32. $p2 = $c2['red'] == 0x00 && $c2['blue']==0xff && $c2['green']==0x00;
  33. $p3 = $c3['red'] == 0x00 && $c3['blue']==0x00 && $c3['green']==0xff;
  34. if ($p1 && $p2 && $p3) {
  35. echo "TC/P: ok\n";
  36. }
  37. imagedestroy($src_tc); imagedestroy($dst_tc);
  38. $src_tc = imagecreate(5,5);
  39. $c0 = imagecolorallocate($src_tc, 0xff, 0xff, 0xff);
  40. $c1 = imagecolorallocate($src_tc, 0xff, 0x00, 0x00);
  41. $c2 = imagecolorallocate($src_tc, 0x00, 0x00, 0xff);
  42. $c3 = imagecolorallocate($src_tc, 0x00, 0xff, 0x00);
  43. imagesetpixel($src_tc, 3,3, $c1);
  44. imagesetpixel($src_tc, 0,0, $c2);
  45. imagesetpixel($src_tc, 4,4, $c3);
  46. $dst_tc = imagecreate(5,5);
  47. imagecopy($dst_tc, $src_tc, 0,0, 0,0, imagesx($src_tc), imagesy($src_tc));
  48. $c1 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 3,3));
  49. $c2 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 0,0));
  50. $c3 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 4,4));
  51. $p1 = $c1['red'] == 0xff && $c1['blue']==0x00 && $c1['green']==0x00;
  52. $p2 = $c2['red'] == 0x00 && $c2['blue']==0xff && $c2['green']==0x00;
  53. $p3 = $c3['red'] == 0x00 && $c3['blue']==0x00 && $c3['green']==0xff;
  54. if ($p1 && $p2 && $p3) {
  55. echo "P/P: ok\n";
  56. }
  57. $src_tc = imagecreate(5,5);
  58. $c0 = imagecolorallocate($src_tc, 0xff, 0xff, 0xff);
  59. $c1 = imagecolorallocate($src_tc, 0xff, 0x00, 0x00);
  60. $c2 = imagecolorallocate($src_tc, 0x00, 0x00, 0xff);
  61. $c3 = imagecolorallocate($src_tc, 0x00, 0xff, 0x00);
  62. imagesetpixel($src_tc, 3,3, $c1);
  63. imagesetpixel($src_tc, 0,0, $c2);
  64. imagesetpixel($src_tc, 4,4, $c3);
  65. $dst_tc = imagecreatetruecolor(5,5);
  66. imagecopy($dst_tc, $src_tc, 0,0, 0,0, imagesx($src_tc), imagesy($src_tc));
  67. $p1 = imagecolorat($dst_tc, 3,3) == 0xff0000;
  68. $p2 = imagecolorat($dst_tc, 0,0) == 0x0000ff;
  69. $p3 = imagecolorat($dst_tc, 4,4) == 0x00ff00;
  70. if ($p1 && $p2 && $p3) {
  71. echo "P/TC: ok\n";
  72. }
  73. ?>
  74. --EXPECT--
  75. TC/TC: ok
  76. TC/P: ok
  77. P/P: ok
  78. P/TC: ok