xref: /php-src/ext/gd/tests/pngcomp.phpt (revision 7b2ca071)
1--TEST--
2png compression test
3--EXTENSIONS--
4gd
5--SKIPIF--
6<?php
7    if (!function_exists("imagecreatefrompng") || !function_exists("imagepng")) {
8        die("skip png support unavailable");
9    }
10?>
11--FILE--
12<?php
13    $cwd = __DIR__;
14
15
16        $im = imagecreatetruecolor(20,20);
17        imagefilledrectangle($im, 5,5, 10,10, 0xffffff);
18	try {
19		imagepng($im, $cwd . '/test_pngcomp.png', -2);
20	} catch (\ValueError $e) {
21		echo $e->getMessage() . PHP_EOL;
22	}
23	try {
24		imagepng($im, $cwd . '/test_pngcomp.png', 10);
25	} catch (\ValueError $e) {
26		echo $e->getMessage() . PHP_EOL;
27	}
28    	echo "PNG compression test: ";
29        imagepng($im, $cwd . '/test_pngcomp.png', 9);
30
31        $im2 = imagecreatefrompng($cwd . '/test_pngcomp.png');
32        $col = imagecolorat($im2, 8,8);
33        if ($col == 0xffffff) {
34                echo "ok\n";
35        }
36
37    @unlink($cwd . "/test_pngcomp.png");
38?>
39--EXPECT--
40imagepng(): Argument #3 ($quality) must be between -1 and 9
41imagepng(): Argument #3 ($quality) must be between -1 and 9
42PNG compression test: ok
43