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