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