xref: /php-src/ext/gd/tests/copy.phpt (revision a375d547)
1--TEST--
2imagecopy
3--EXTENSIONS--
4gd
5--FILE--
6<?php
7
8$src_tc = imagecreatetruecolor(5,5);
9imagefill($src_tc, 0,0, 0xffffff);
10imagesetpixel($src_tc, 3,3, 0xff0000);
11imagesetpixel($src_tc, 0,0, 0x0000ff);
12imagesetpixel($src_tc, 4,4, 0x00ff00);
13
14
15$dst_tc = imagecreatetruecolor(5,5);
16imagecopy($dst_tc, $src_tc, 0,0, 0,0, imagesx($src_tc), imagesy($src_tc));
17$p1 = imagecolorat($dst_tc, 3,3) == 0xff0000;
18$p2 = imagecolorat($dst_tc, 0,0) == 0x0000ff;
19$p3 = imagecolorat($dst_tc, 4,4) == 0x00ff00;
20
21if ($p1 && $p2 && $p3) {
22    echo "TC/TC: ok\n";
23}
24
25imagedestroy($src_tc); imagedestroy($dst_tc);
26
27
28$src_tc = imagecreatetruecolor(5,5);
29imagefill($src_tc, 0,0, 0xffffff);
30imagesetpixel($src_tc, 3,3, 0xff0000);
31imagesetpixel($src_tc, 0,0, 0x0000ff);
32imagesetpixel($src_tc, 4,4, 0x00ff00);
33
34
35$dst_tc = imagecreate(5,5);
36imagecopy($dst_tc, $src_tc, 0,0, 0,0, imagesx($src_tc), imagesy($src_tc));
37
38$c1 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 3,3));
39$c2 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 0,0));
40$c3 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 4,4));
41
42$p1 = $c1['red'] == 0xff && $c1['blue']==0x00 && $c1['green']==0x00;
43$p2 = $c2['red'] == 0x00 && $c2['blue']==0xff && $c2['green']==0x00;
44$p3 = $c3['red'] == 0x00 && $c3['blue']==0x00 && $c3['green']==0xff;
45
46if ($p1 && $p2 && $p3) {
47    echo "TC/P: ok\n";
48}
49imagedestroy($src_tc); imagedestroy($dst_tc);
50
51
52
53$src_tc = imagecreate(5,5);
54$c0 = imagecolorallocate($src_tc, 0xff, 0xff, 0xff);
55$c1 = imagecolorallocate($src_tc, 0xff, 0x00, 0x00);
56$c2 = imagecolorallocate($src_tc, 0x00, 0x00, 0xff);
57$c3 = imagecolorallocate($src_tc, 0x00, 0xff, 0x00);
58
59imagesetpixel($src_tc, 3,3, $c1);
60imagesetpixel($src_tc, 0,0, $c2);
61imagesetpixel($src_tc, 4,4, $c3);
62
63
64$dst_tc = imagecreate(5,5);
65imagecopy($dst_tc, $src_tc, 0,0, 0,0, imagesx($src_tc), imagesy($src_tc));
66
67$c1 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 3,3));
68$c2 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 0,0));
69$c3 = imagecolorsforindex($dst_tc, imagecolorat($dst_tc, 4,4));
70
71$p1 = $c1['red'] == 0xff && $c1['blue']==0x00 && $c1['green']==0x00;
72$p2 = $c2['red'] == 0x00 && $c2['blue']==0xff && $c2['green']==0x00;
73$p3 = $c3['red'] == 0x00 && $c3['blue']==0x00 && $c3['green']==0xff;
74
75
76if ($p1 && $p2 && $p3) {
77    echo "P/P: ok\n";
78}
79
80
81
82$src_tc = imagecreate(5,5);
83$c0 = imagecolorallocate($src_tc, 0xff, 0xff, 0xff);
84$c1 = imagecolorallocate($src_tc, 0xff, 0x00, 0x00);
85$c2 = imagecolorallocate($src_tc, 0x00, 0x00, 0xff);
86$c3 = imagecolorallocate($src_tc, 0x00, 0xff, 0x00);
87
88imagesetpixel($src_tc, 3,3, $c1);
89imagesetpixel($src_tc, 0,0, $c2);
90imagesetpixel($src_tc, 4,4, $c3);
91
92
93$dst_tc = imagecreatetruecolor(5,5);
94imagecopy($dst_tc, $src_tc, 0,0, 0,0, imagesx($src_tc), imagesy($src_tc));
95$p1 = imagecolorat($dst_tc, 3,3) == 0xff0000;
96$p2 = imagecolorat($dst_tc, 0,0) == 0x0000ff;
97$p3 = imagecolorat($dst_tc, 4,4) == 0x00ff00;
98
99if ($p1 && $p2 && $p3) {
100    echo "P/TC: ok\n";
101}
102?>
103--EXPECT--
104TC/TC: ok
105TC/P: ok
106P/P: ok
107P/TC: ok
108