Monday, December 22, 2025
HomeLanguagesPHP | Imagick valid() Function

PHP | Imagick valid() Function

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
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
try {
  
    // Create a new imagick object with valid image
    $imagick = new Imagick(
    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

RELATED ARTICLES

Most Popular

Dominic
32456 POSTS0 COMMENTS
Milvus
111 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12038 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6911 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS