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