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