xref: /PHP-8.2/ext/gd/tests/imagecrop_auto.phpt (revision a375d547)
1--TEST--
2Testing imagecropauto()
3--EXTENSIONS--
4gd
5--SKIPIF--
6<?php
7if (!function_exists('imagecrop')) die( 'skip GD imagecropauto not present; skipping test' );
8?>
9--FILE--
10<?php
11
12echo "TC IMG_CROP_DEFAULT\n";
13$im = imagecreatetruecolor(99, 99);
14imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
15$im_crop = imagecropauto($im, IMG_CROP_DEFAULT);
16var_dump(imagesx($im_crop));
17var_dump(imagesy($im_crop));
18
19echo "Palette IMG_CROP_DEFAULT\n";
20$im = imagecreate(99, 99);
21imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
22$im_crop = imagecropauto($im, IMG_CROP_DEFAULT);
23var_dump(imagesx($im_crop));
24var_dump(imagesy($im_crop));
25
26echo "TC IMG_CROP_SIDES\n";
27$im = imagecreatetruecolor(99, 99);
28imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
29$im_crop = imagecropauto($im, IMG_CROP_SIDES);
30var_dump(imagesx($im_crop));
31var_dump(imagesy($im_crop));
32
33echo "Palette IMG_CROP_SIDES\n";
34$im = imagecreate(99, 99);
35imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
36$im_crop = imagecropauto($im, IMG_CROP_SIDES);
37var_dump(imagesx($im_crop));
38var_dump(imagesy($im_crop));
39
40echo "TC IMG_CROP_BLACK\n";
41$im = imagecreatetruecolor(50, 50);
42imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
43$im_crop = imagecropauto($im, IMG_CROP_BLACK);
44var_dump(imagesx($im_crop));
45var_dump(imagesy($im_crop));
46
47echo "Palette IMG_CROP_BLACK\n";
48$im = imagecreate(50, 50);
49$bgd = imagecolorallocate($im, 0, 0, 0);
50$b = imagecolorallocate($im, 0, 0, 255);
51imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
52$im_crop = imagecropauto($im, IMG_CROP_BLACK);
53var_dump(imagesx($im_crop));
54var_dump(imagesy($im_crop));
55
56echo "IMG_CROP_THRESHOLD\n";
57$im = imagecreatefrompng(__DIR__ . "/logo_noise.png");
58$im_crop = imagecropauto($im, IMG_CROP_THRESHOLD, 0.1, 0x0);
59imagepng($im_crop, __DIR__ . "/crop_threshold.png");
60var_dump(imagesx($im_crop));
61var_dump(imagesy($im_crop));
62
63@unlink(__DIR__ . "/crop_threshold.png");
64?>
65--EXPECT--
66TC IMG_CROP_DEFAULT
67int(99)
68int(99)
69Palette IMG_CROP_DEFAULT
70int(99)
71int(99)
72TC IMG_CROP_SIDES
73int(11)
74int(11)
75Palette IMG_CROP_SIDES
76int(11)
77int(11)
78TC IMG_CROP_BLACK
79int(11)
80int(11)
81Palette IMG_CROP_BLACK
82int(11)
83int(11)
84IMG_CROP_THRESHOLD
85int(240)
86int(134)
87