Skip to content

imagecropauto() not working with transparent background #13163

Open
@ThomasLandauer

Description

@ThomasLandauer

Description

The following code:

<?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
$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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions