How can the "imagesx()" function in PHP be used properly to avoid the "supplied argument is not a valid Image resource" warning?

When using the "imagesx()" function in PHP, it is important to ensure that the argument passed to the function is a valid image resource. To avoid the "supplied argument is not a valid Image resource" warning, you should first check if the image is a valid resource using the "is_resource()" function. If the image is a valid resource, then you can safely use the "imagesx()" function to get the width of the image.

// Check if $image is a valid image resource
if (is_resource($image)) {
    // Get the width of the image
    $width = imagesx($image);
    // Use the width as needed
} else {
    // Handle the case where $image is not a valid image resource
    echo "Error: Not a valid image resource";
}