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