You are here

public function ImageStylesWarmer::validateImage in Image Style Warmer 8

Validate file as an image file.

Parameters

\Drupal\file\FileInterface $file: The file for which image styles should be created.

Overrides ImageStylesWarmerInterface::validateImage

2 calls to ImageStylesWarmer::validateImage()
ImageStylesWarmer::addQueue in src/ImageStylesWarmer.php
Add file and image styles to ImageStylesPregenerator queue.
ImageStylesWarmer::doWarmUp in src/ImageStylesWarmer.php
Do warm up of image styles for an image file.

File

src/ImageStylesWarmer.php, line 146

Class

ImageStylesWarmer
Defines an images styles warmer.

Namespace

Drupal\image_style_warmer

Code

public function validateImage(FileInterface $file) {
  if ($file
    ->isPermanent()) {
    $image = $this->image
      ->get($file
      ->getFileUri());
    $extensions = implode(' ', $image
      ->getToolkit()
      ->getSupportedExtensions());
    if ($image
      ->isValid() && empty(file_validate_extensions($file, $extensions))) {
      return TRUE;
    }
  }
  return FALSE;
}