PHP | Imagick valid() Function

Last Updated : 23 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The Imagick::valid() function is an inbuilt function in PHP which is used to check if the current item is valid. Syntax:
bool Imagick::valid( void )
Parameters: This function doesn’t accept any parameter. Return Value: This function returns TRUE on success. Exceptions: This function throws ImagickException on error. Below given programs illustrate the Imagick::valid() function in PHP: Program 1: php
<?php
try {

    // Create a new imagick object with invalid image
    $imagick = new Imagick('undefined_source');
    if ($imagick->valid()) {
        echo 'Image is valid';
    }
} catch (exception $e) {
    echo 'Image is not valid';
}
?>
Output:
Image is not valid
Program 2: php
<?php
try {

    // Create a new imagick object with valid image
    $imagick = new Imagick(
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');
    if ($imagick->valid()) {
        echo 'Image is valid';
    }
} catch (exception $e) {
    echo 'Image is not valid';
}
?>
Output:
Image is valid
Reference: https://www.php.net/manual/en/imagick.valid.php

Next Article

Similar Reads