xref: /PHP-7.2/ext/gd/tests/copypalette.phpt (revision 17ccbeec)
1--TEST--
2imagepalettecopy
3--SKIPIF--
4<?php
5        if (!function_exists('imagecolorat')) die("skip gd extension not available\n");
6?>
7--FILE--
8<?php
9$failed = false;
10$im = imagecreate(1,1);
11for ($i=0; $i<256; $i++) {
12	imagecolorallocate($im, $i, $i, $i);
13}
14
15$im2 = imagecreate(1,1);
16imagepalettecopy($im2, $im);
17
18for ($i=0; $i<256; $i++) {
19	$c = imagecolorsforindex($im2, $i);
20	if ($c['red']!=$i || $c['green']!=$i || $c['blue']!=$i) {
21		$failed = true;
22		break;
23	}
24}
25echo "copy palette 255 colors: ";
26echo $failed ? 'failed' : 'ok';
27echo "\n";
28
29$im = imagecreate(1,1);
30$im2 = imagecreate(1,1);
31imagecolorallocatealpha($im, 0,0,0,100);
32
33imagepalettecopy($im2, $im);
34$c = imagecolorsforindex($im2, 0);
35if ($c['red']!=0 || $c['green']!=0 || $c['blue']!=0 || $c['alpha']!=100) {
36	$failed = true;
37}
38echo 'copy palette 1 color and alpha: ';
39echo $failed ? 'failed' : 'ok';
40echo "\n";
41?>
42--EXPECT--
43copy palette 255 colors: ok
44copy palette 1 color and alpha: ok
45