Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images not destroyed? #325

Closed
rasteiner opened this issue Jun 5, 2023 · 1 comment · Fixed by #326
Closed

Images not destroyed? #325

rasteiner opened this issue Jun 5, 2023 · 1 comment · Fixed by #326

Comments

@rasteiner
Copy link
Contributor

Since PHP8 the GD functions work with the GdImage class and no longer with resources.
The __destruct function:

public function __destruct()
{
//Check for a valid GDimage instance
$type_check = (gettype($this->image) == 'object' && $this->image::class == 'GdImage');
if (is_resource($this->image) && $type_check) {
imagedestroy($this->image);
}
}

however checks if the the current image is both a GdImage as well as a resource. But as far as I can test, GdImages are not resources:

$img = imagecreatetruecolor(10,10);

var_dump($img); // instance of class GdImage
var_dump(is_resource($img)); // false

Run code in sandbox

Therefore the conditions are never met and the image is never destroyed.

Since PHP 7 support has been dropped, the function could be rewritten as:

    protected $image = null;

    // snip

    /**
     * Destroys the image resource.
     */
    public function __destruct()
    {
        if ($this->image instanceof \GdImage) {
            imagedestroy($this->image);
        }
    }
@claviska
Copy link
Owner

claviska commented Jun 5, 2023

Good catch. This was left over from a much earlier version — perhaps PHP 5.6. Would you like to send a PR for this update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants