xref: /PHP-8.0/ext/gd/tests/bug67447.phpt (revision c5401854)
1--TEST--
2Bug #67447 (imagecrop() adds a black line when cropping)
3--SKIPIF--
4<?php
5    if (!extension_loaded('gd')) {
6        die("skip gd extension not available\n");
7    }
8?>
9--FILE--
10<?php
11// true color
12$image = imagecreatetruecolor(500, 500);
13$red = imagecolorallocate($image, 255, 0, 0);
14imagefill($image, 0, 0, $red);
15$cropped = imagecrop($image, ['x' => 0, 'y' => 0, 'width' => 250, 'height' => 250]);
16var_dump(imagecolorat($cropped, 249, 249) === $red);
17imagedestroy($image);
18imagedestroy($cropped);
19
20// palette
21$image = imagecreate(500, 500);
22imagecolorallocate($image, 0, 0, 255); // first palette color = background
23$red = imagecolorallocate($image, 255, 0, 0);
24imagefill($image, 0, 0, $red);
25$cropped = imagecrop($image, ['x' => 0, 'y' => 0, 'width' => 250, 'height' => 250]);
26var_dump(imagecolorsforindex($cropped, imagecolorat($cropped, 249, 249)));
27imagedestroy($image);
28imagedestroy($cropped);
29?>
30--EXPECT--
31bool(true)
32array(4) {
33  ["red"]=>
34  int(255)
35  ["green"]=>
36  int(0)
37  ["blue"]=>
38  int(0)
39  ["alpha"]=>
40  int(0)
41}
42