Check if its a file or image so we know what to render.

@param \Drupal\file\FileInterface $file
A file entity. This function may resize the file affecting its size.

@return bool
TRUE when it's an image and not a file
14557
private function isImage(FileInterface $file) {
    $image = $this->getImage($file);

    if ($image === NULL) {
      return FALSE;
    }

    return $image->isValid();
  }
1095461
public function filter(\SplFileInfo $file)
    {
        if ($this->minsize !== null && $this->minsize > $file->getSize()) {
            return false;
        }
        if ($this->maxsize !== null && $this->maxsize < $file->getSize()) {
            return false;
        }

        return true;
    }
1136609
public function renderFile(File &$file)
    {
        if ($file->isRendered()) {
            return;
        }
        $fileRenderer = $this->get($file->getExt());
        $file->setContent($fileRenderer->render($file));
        $file->setExt($fileRenderer->getDestinationExtension($file->getExt()));
        $file->setRendered(true);
        $fileRenderer->mutateFile($file);
    }
351646
protected function checkFileReadable($file)
    {
        if (!file_exists($file)) {
            throw new \RuntimeException("File [$file] does not exist");
        }
        if (!is_file($file)) {
            throw new \RuntimeException("File [$file] is not a file");
        }
        if (!is_readable($file)) {
            throw new \RuntimeException("File [$file] is not readable");
        }
    }
995924
public function isSafe($file)
	{
		$file = Util::normalizePath($file);

		return (bool) $this->adapter->isSafe($file);
	}
1015164
public static function resizeImage($file, $width, $height, $desFile = '')
    {
        try {
            if (is_file($file)) {
                if (!$desFile) {
                    $desFile = $file;
                }
                Image::open($file)->resize($width, $height)->save($desFile);
                return true;
            }
        } catch (Exception $e) {
        }
        return false;
    }
1209391
public function isCoreFile($file) {

        return true;
        return $file === null || strpos(realpath($file), YII2_PATH . DIRECTORY_SEPARATOR) === 0;
    }
679547
public function downloadFile(FileInterface $file)
    {
        /**
         * @var string $content
         */
        $content = $this
            ->filesystem
            ->read($this
                ->fileIdentifierTransformer
                ->transform($file)
            );

        $file->setContent($content);

        return $file;
    }
221545
public function delFile($file)
    {
        $file = $this->checkpath($file);
        if (@!ftp_delete($this->linkid, $file)) {
            $this->close();
            return false;
        }
        $this->close();
        return true;
    }
833517
private function isInsideImage(ImageInterface $image, $x, $y, $width, $height)
    {
        if ($x < 0 || $y < 0) {
            return false;
        }
        if ($x + $width > $image->getSize()->getWidth()) {
            return false;
        }
        if ($y + $height > $image->getSize()->getHeight()) {
            return false;
        }

        return true;
    }
1048198
public static function checkFileDeletable($file)
    {
        clearstatcache();
        $dir = dirname($file);
        // Deleting a file requires write permissions on the directory.
        // It does not require write permissions on the file
        return @file_exists($dir) && @is_writable($dir);
    }
940203
private function shouldCopyFileInstead($file)
    {
        // Check if it should not be processed.
        if ($this->isExcludedFromVerbatim($file)) {
            return false;
        }

        foreach ($this->copyVerbatimPatterns as $pattern) {
            if (Str::is($pattern, $file)) {
                return true;
            }
        }

        return false;
    }
277923
public function loadImageDetails($file = null)
    {
        $file = $file ? $file : $this->pathToImage;

        is_readable($file)
            or $this->raiseError('Image file does not exist.');

        $info = list($this->width, $this->height, $this->fileType) = getimagesize($file);
        if (empty($info)) {
            // To support webp
            $this->fileType = false;
            if (function_exists("exif_imagetype")) {
                $this->fileType = exif_imagetype($file);
                if ($this->fileType === false) {
                    if (function_exists("imagecreatefromwebp")) {
                        $webp = imagecreatefromwebp($file);
                        if ($webp !== false) {
                            $this->width  = imagesx($webp);
                            $this->height = imagesy($webp);
                            $this->fileType = IMG_WEBP;
                        }
                    }
                }
            }
        }

        if (!$this->fileType) {
            throw new Exception("Loading image details, the file doesn't seem to be a valid image.");
        }

        if ($this->verbose) {
            $this->log("Loading image details for: {$file}");
            $this->log(" Image width x height (type): {$this->width} x {$this->height} ({$this->fileType}).");
            $this->log(" Image filesize: " . filesize($file) . " bytes.");
            $this->log(" Image mimetype: " . $this->getMimeType());
        }

        return $this;
    }
143311
public function lint($file)
    {
        $template = $this->app['twig.loader.viewfinder']->getSourceContext($file);

        if (!$template) {
            throw new InvalidArgumentException('Unable to find file: '.$file);
        }

        try {
            $this->parse($this->tokenize($template, $file));
        } catch (Error $e) {
            return false;
        }

        return true;
    }
1285231
public function onAfterLoadIntoFile($file)
    {
        // return if not an image
        if (!$file->getIsImage()) {
            return;
        }

        // get parent folder path
        $folder = rtrim($file->Parent()->getFilename(), '/');

        $custom_folders = $this->config()->get('custom_folders');

        if (!empty($custom_folders[$folder]) && is_array($custom_folders[$folder])) {
            foreach ($custom_folders[$folder] as $key => $val) {
                $this->config()->set($key, $val);
            }
        }

        if ($this->config()->get('bypass')) {
            return;
        }

        $this->config_max_width = $this->config()->get('max_width');
        $this->config_max_height = $this->config()->get('max_height');
        $this->config_auto_rotate = $this->config()->get('auto_rotate');
        $this->config_force_resampling = $this->config()->get('force_resampling');

        $extension = $file->getExtension();

        if ($this->config_force_resampling ||
            ($this->config_max_height && $file->getHeight() > $this->config_max_height) ||
            ($this->config_max_width && $file->getWidth() > $this->config_max_width) ||
            ($this->config_auto_rotate && preg_match('/jpe?g/i', $file->getExtension()))
        ) {
            $this->scaleUploadedImage($file);
        }
    }
519386
public static function isFileReadable($file)
    {
        $result = false;

        if (!file_exists($file)) {
            return $result;
        }
        if (!is_file($file)) {
            return $result;
        }
        if (!is_readable($file)) {
            return $result;
        }

        $result = true;

        return $result;
    }
1339708
public function delete(FileInterface $file)
    {

        if(isset($this->fs[$file->getPath()])){
            unset($this->fs[$file->getPath()]);
        }
        if($dir = $file->getDir()){
            $dir->removeChild($file);
        }
        return $this;

    }