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