1
0
mirror of https://github.com/php/php-src.git synced 2026-04-28 02:33:17 +02:00
Files
archived-php-src/ext/gd/tests/imagecrop_auto.phpt
T
Christoph M. Becker 947ca9f43d Sync behavior of gdImageAutoCrop() with upstream
Since cropping support has been added to our bundled libgd,
`gdImageAutoCrop` differs from upstream in that `GD_CROP_DEFAULT` falls
back on `GD_CROP_SIDES` if there is no transparent color in the image.
While this difference seem to be a useful improvement in our bundled
libgd, upstream has not yet signaled that there willing to back-port
it[1], so we revert it to stay in sync with upstream.

We also remove the additional NULL bailout at the end of the function,
which doesn't appear to be relevant any longer since bug 77198 has been
fixed.

[1] <https://github.com/libgd/libgd/issues/298>
2018-12-01 15:34:10 +01:00

85 lines
2.1 KiB
PHP

--TEST--
Testing imagecropauto()
--SKIPIF--
<?php
if ( ! extension_loaded('gd') || !function_exists('imagecrop')) die( 'skip GD imagecropauto not present; skipping test' );
?>
--FILE--
<?php
echo "TC IMG_CROP_DEFAULT\n";
$im = imagecreatetruecolor(99, 99);
imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
$im_crop = imagecropauto($im, IMG_CROP_DEFAULT);
var_dump(imagesx($im_crop));
var_dump(imagesy($im_crop));
echo "Palette IMG_CROP_DEFAULT\n";
$im = imagecreate(99, 99);
imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
$im_crop = imagecropauto($im, IMG_CROP_DEFAULT);
var_dump(imagesx($im_crop));
var_dump(imagesy($im_crop));
echo "TC IMG_CROP_SIDES\n";
$im = imagecreatetruecolor(99, 99);
imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
$im_crop = imagecropauto($im, IMG_CROP_SIDES);
var_dump(imagesx($im_crop));
var_dump(imagesy($im_crop));
echo "Palette IMG_CROP_SIDES\n";
$im = imagecreate(99, 99);
imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
$im_crop = imagecropauto($im, IMG_CROP_SIDES);
var_dump(imagesx($im_crop));
var_dump(imagesy($im_crop));
echo "TC IMG_CROP_BLACK\n";
$im = imagecreatetruecolor(50, 50);
imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
$im_crop = imagecropauto($im, IMG_CROP_BLACK);
var_dump(imagesx($im_crop));
var_dump(imagesy($im_crop));
echo "Palette IMG_CROP_BLACK\n";
$im = imagecreate(50, 50);
$bgd = imagecolorallocate($im, 0, 0, 0);
$b = imagecolorallocate($im, 0, 0, 255);
imagefilledrectangle($im, 20, 20, 30, 30, 0xff);
$im_crop = imagecropauto($im, IMG_CROP_BLACK);
var_dump(imagesx($im_crop));
var_dump(imagesy($im_crop));
echo "IMG_CROP_THRESHOLD\n";
$im = imagecreatefrompng(__DIR__ . "/logo_noise.png");
$im_crop = imagecropauto($im, IMG_CROP_THRESHOLD, 0.1, 0x0);
imagepng($im_crop, __DIR__ . "/crop_threshold.png");
var_dump(imagesx($im_crop));
var_dump(imagesy($im_crop));
@unlink(__DIR__ . "/crop_threshold.png");
?>
--EXPECT--
TC IMG_CROP_DEFAULT
int(99)
int(99)
Palette IMG_CROP_DEFAULT
int(99)
int(99)
TC IMG_CROP_SIDES
int(11)
int(11)
Palette IMG_CROP_SIDES
int(11)
int(11)
TC IMG_CROP_BLACK
int(11)
int(11)
Palette IMG_CROP_BLACK
int(11)
int(11)
IMG_CROP_THRESHOLD
int(240)
int(134)