A way to check if a variable is a valid GD image resource?

I have a class that takes a GD image resource as one of its arguments. As far as I know, there is no way to type hint this, as this is a resource, not an object. Is there any way to check if the provided argument is a valid GD image resource (other than additional functions using this resource)?

PS: Please do not mention ImageMagick in your answer ...

+6
source share
2 answers

The get_resource_type function should help you. Except for writing the code and looking at what it returns, I'm not sure what it will say for the GD resource, so you are on your own. Should be a good starting point though!

+6
source

get_resource_type () returns "gd" if the resource is a gd image, so you need to.

+8
source

Source: https://habr.com/ru/post/887776/


All Articles