copy.phpt 3.0 KB

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