[php-src] Issue #13163: `imagecropauto()` not working with transparent background
| From: | ThomasLandauer | Date: | Tue, 16 Jan 2024 13:06:39 +0000 |
| Subject: | [php-src] Issue #13163: `imagecropauto()` not working with transparent background | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246268@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13163
Author: ThomasLandauer
### Description
The following code:
```php
<?php
$gdImage = imagecreatetruecolor(100,100);
imagesavealpha($gdImage, true);
imagefill($gdImage, 0, 0, imagecolorallocatealpha($gdImage, 0, 0, 0, 127));
// imagepng($gdImage, '/tmp/image_transparent.png');
$result = imagecropauto($gdImage, IMG_CROP_TRANSPARENT);
var_dump($result); // object(GdImage)#2 (0) { }
// imagepng($result, '/tmp/image_black.png');
```
Resulted in this output:
```
object(GdImage)#2 (0) { }
```
But I expected this output instead:
```
bool(false)
```
Docs at https://www.php.net/manual/en/function.imagecropauto.php
are saying:
> If the complete image was cropped,
imagecrop() returns false
And this should be the case here IMO.
When doing the same with white background, it works as expected:
```php
<?php
$gdImage = imagecreatetruecolor(100,100);
imagesavealpha($gdImage, true);
imagefill($gdImage, 0, 0, imagecolorallocate($gdImage, 255, 255, 255));
// imagepng($gdImage, '/tmp/image_white.png');
$result = imagecropauto($gdImage, IMG_CROP_WHITE);
var_dump($result); // bool(false)
```
### PHP Version
PHP 8.3.1
### Operating System
Kubuntu 22.04