xref: /PHP-7.3/ext/gd/tests/imagefilter.phpt (revision 782352c5)
1--TEST--
2imagefilter() function test
3--SKIPIF--
4<?php
5	if (!extension_loaded('gd')) {
6		die("skip gd extension not available.");
7	}
8	if (!function_exists("imagefilter")) die("skip requires bundled GD library\n");
9?>
10--FILE--
11<?php
12$no_arg_filters = array(
13	"IMG_FILTER_NEGATE",
14	"IMG_FILTER_GRAYSCALE",
15	"IMG_FILTER_EDGEDETECT",
16	"IMG_FILTER_GAUSSIAN_BLUR",
17	"IMG_FILTER_SELECTIVE_BLUR",
18	"IMG_FILTER_EMBOSS",
19	"IMG_FILTER_MEAN_REMOVAL"
20);
21
22$SAVE_DIR = dirname(__FILE__);
23$SOURCE_IMG = $SAVE_DIR . "/test.png";
24
25	foreach ($no_arg_filters as $filt) {
26		$im = imagecreatefrompng($SOURCE_IMG);
27		if (imagefilter($im, constant($filt))) {
28			imagepng($im, $SAVE_DIR."/".$filt. ".png");
29			echo "$filt success\n";
30			@unlink($SAVE_DIR."/".$filt. ".png");
31		} else {
32			echo "$filt failed\n";
33		}
34	}
35
36	$im = imagecreatefrompng($SOURCE_IMG);
37
38	if (imagefilter($im, IMG_FILTER_SMOOTH, -1924.124)) {
39		imagepng($im, $SAVE_DIR . "/IMG_FILTER_SMOOTH.png");
40		echo "IMG_FILTER_SMOOTH success\n";
41		@unlink($SAVE_DIR . "/IMG_FILTER_SMOOTH.png");
42	} else {
43		echo "IMG_FILTER_SMOOTH failed\n";
44	}
45
46	$im = imagecreatefrompng($SOURCE_IMG);
47
48	if (imagefilter($im, IMG_FILTER_COLORIZE, -127.12, -127.98, 127)) {
49		imagepng($im, $SAVE_DIR . "/IMG_FILTER_COLORIZE.png");
50		echo "IMG_FILTER_COLORIZE success\n";
51		unlink($SAVE_DIR . "/IMG_FILTER_COLORIZE.png");
52	} else {
53		echo "IMG_FILTER_COLORIZE failed\n";
54	}
55
56	$im = imagecreatefrompng($SOURCE_IMG);
57
58	if (imagefilter($im, IMG_FILTER_CONTRAST, -90)) {
59		imagepng($im, $SAVE_DIR . "/IMG_FILTER_CONTRAST.png");
60		echo "IMG_FILTER_CONTRAST success\n";
61		unlink($SAVE_DIR . "/IMG_FILTER_CONTRAST.png");
62	} else {
63		echo "IMG_FILTER_CONTRAST failed\n";
64	}
65
66	$im = imagecreatefrompng($SOURCE_IMG);
67
68	if (imagefilter($im, IMG_FILTER_BRIGHTNESS, 98)) {
69		imagepng($im, $SAVE_DIR . "/IMG_FILTER_BRIGHTNESS.png");
70		echo "IMG_FILTER_BRIGHTNESS success\n";
71		unlink($SAVE_DIR . "/IMG_FILTER_BRIGHTNESS.png");
72	} else {
73		echo "IMG_FILTER_BRIGHTNESS failed\n";
74	}
75
76	$im = imagecreatefrompng($SOURCE_IMG);
77
78	if (imagefilter($im, IMG_FILTER_PIXELATE, 5, true)) {
79		imagepng($im, $SAVE_DIR . "/IMG_FILTER_PIXELATE.png");
80		echo "IMG_FILTER_PIXELATE success\n";
81		unlink($SAVE_DIR . "/IMG_FILTER_PIXELATE.png");
82	} else {
83		echo "IMG_FILTER_PIXELATE failed\n";
84	}
85?>
86--EXPECT--
87IMG_FILTER_NEGATE success
88IMG_FILTER_GRAYSCALE success
89IMG_FILTER_EDGEDETECT success
90IMG_FILTER_GAUSSIAN_BLUR success
91IMG_FILTER_SELECTIVE_BLUR success
92IMG_FILTER_EMBOSS success
93IMG_FILTER_MEAN_REMOVAL success
94IMG_FILTER_SMOOTH success
95IMG_FILTER_COLORIZE success
96IMG_FILTER_CONTRAST success
97IMG_FILTER_BRIGHTNESS success
98IMG_FILTER_PIXELATE success
99