function file_validate_is_image

7.x file_validate_is_image(stdClass $file)
6.x file_validate_is_image(&$file)
8.x file.module file_validate_is_image(FileInterface $file)

Checks that the file is recognized by image_get_info() as an image.


$file: A Drupal file object.

Return value

An array. If the file is not an image, it will contain an error message.

See also


Related topics

1 call to file_validate_is_image()
FileValidatorTest::testFileValidateIsImage in drupal/modules/simpletest/tests/file.test
This ensures a specific file is actually an image.
3 string references to 'file_validate_is_image'
system_theme_settings_validate in drupal/modules/system/
Validator for the system_theme_settings() form.
user_validate_picture in drupal/modules/user/user.module
Validates an image uploaded by a user.
_file_test_form_submit in drupal/modules/simpletest/tests/file_test.module
Process the upload.


drupal/includes/, line 1774
API for handling file uploads and server file management.


function file_validate_is_image(stdClass $file) {
  $errors = array();

  $info = image_get_info($file->uri);
  if (!$info || empty($info['extension'])) {
    $errors[] = t('Only JPEG, PNG and GIF images are allowed.');

  return $errors;