Checks that the file is recognized by image_get_info() as an image.
Drupal\file\File $file: A file entity.
An array. If the file is not an image, it will contain an error message.
function file_validate_is_image(File $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;
}