xref: /PHP-8.1/ext/gd/tests/copyresized.phpt (revision a375d547)
1--TEST--
2imagecopyresized
3--EXTENSIONS--
4gd
5--FILE--
6<?php
7
8function get_hexcolor($im, $c) {
9    if (imageistruecolor($im)) {
10        return $c;
11    }
12    $colors = imagecolorsforindex($im, $c);
13    return ($colors['red'] << 16)  + ($colors['green'] << 8) + ($colors['blue']);
14}
15
16function check_doublesize($dst) {
17    $im = imagecreatetruecolor(38,38);
18    imagefill($im,0,0, 0xffffff);
19    imagefilledrectangle($im, 0,0,9,9, 0xff0000);
20    imagefilledrectangle($im, 0,28,9,37, 0xff0000);
21    imagefilledrectangle($im, 28,0,37,9, 0xff0000);
22    imagefilledrectangle($im, 28,28,37,37, 0xff0000);
23    imagefilledrectangle($im, 14,14,23,23, 0xff0000);
24
25    for ($x = 0; $x < 38; $x++) {
26        for ($y = 0; $y < 38; $y++) {
27            $p1 = imagecolorat($im, $x, $y);
28            $p2 = imagecolorat($dst, $x, $y);
29            if (get_hexcolor($im, $p1) != get_hexcolor($dst, $p2)) {
30                return false;
31            }
32        }
33    }
34    return true;
35}
36
37$src_tc = imagecreatetruecolor(19,19);
38imagefill($src_tc, 0,0, 0xffffff);
39imagefilledrectangle($src_tc, 0,0,4,4, 0xff0000);
40imagefilledrectangle($src_tc, 14,0,18,4, 0xff0000);
41imagefilledrectangle($src_tc, 0,14,4,18, 0xff0000);
42imagefilledrectangle($src_tc, 14,14,18,18, 0xff0000);
43imagefilledrectangle($src_tc, 7,7,11,11, 0xff0000);
44
45$dst_tc = imagecreatetruecolor(38,38);
46imagecopyresized($dst_tc, $src_tc, 0,0, 0,0, imagesx($dst_tc), imagesy($dst_tc), 19,19);
47
48if (!check_doublesize($dst_tc)) exit("1 failed\n");
49echo "TC->TC: ok\n";
50
51$src_tc = imagecreate(19,19);
52$white = imagecolorallocate($src_tc, 255,255,255);
53$red = imagecolorallocate($src_tc, 255,0,0);
54
55imagefilledrectangle($src_tc, 0,0,4,4, $red);
56imagefilledrectangle($src_tc, 14,0,18,4, $red);
57imagefilledrectangle($src_tc, 0,14,4,18, $red);
58imagefilledrectangle($src_tc, 14,14,18,18, $red);
59imagefilledrectangle($src_tc, 7,7,11,11, $red);
60
61$dst_tc = imagecreatetruecolor(38,38);
62imagecopyresized($dst_tc, $src_tc, 0,0, 0,0, imagesx($dst_tc), imagesy($dst_tc), 19,19);
63
64if (!check_doublesize($dst_tc)) exit("2 failed\n");
65echo "P->TC: ok\n";
66
67$src_tc = imagecreate(19,19);
68$white = imagecolorallocate($src_tc, 255,255,255);
69$red = imagecolorallocate($src_tc, 255,0,0);
70
71imagefilledrectangle($src_tc, 0,0,4,4, $red);
72imagefilledrectangle($src_tc, 14,0,18,4, $red);
73imagefilledrectangle($src_tc, 0,14,4,18, $red);
74imagefilledrectangle($src_tc, 14,14,18,18, $red);
75imagefilledrectangle($src_tc, 7,7,11,11, $red);
76
77$dst_tc = imagecreate(38,38);
78$white = imagecolorallocate($src_tc, 255,255,255);
79$red = imagecolorallocate($src_tc, 255,0,0);
80
81imagecopyresized($dst_tc, $src_tc, 0,0, 0,0, imagesx($dst_tc), imagesy($dst_tc), 19,19);
82
83if (!check_doublesize($dst_tc)) exit("3 failed\n");
84echo "P->P: ok\n";
85?>
86--EXPECT--
87TC->TC: ok
88P->TC: ok
89P->P: ok
90