Load an image type by extension

@param string $extension Extension of image
771471
protected function loadExtension($extension)
	{
		if (isset($this->classMap[$extension]))
		{
			return;
		}
		foreach ($this->supportedTypes as $imageType => $extensions)
		{
			if (in_array($extension, $extensions, true))
			{
				$this->loadType($imageType);
			}
		}
	}
1310344
public function setTypeFromFilename($filename)
    {
        $extension = $this->getExtensionFromFilename($filename);

        if ( empty($extension) ) {
            throw new InvalidFileExtensionException("You must specify an image extension.");
        }

        return $this->setTypeFromExtension($extension);
    }
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;
    }
963029
public static function assumeExtensionLoaded($extension, $message = ''): void
    {
        assumeThat(\extension_loaded($extension), is(true), $message);
    }
991659
public static boolean isImage(String extension)
  {
    return extension != null ? IMAGE_FILE_EXTENSIONS.contains(extension.toLowerCase()) : false;
  }
382979
private function shouldOptimizeByExtension(string $extension, array $validExtensions): bool
    {
        return \in_array($extension === 'jpeg' ? 'jpg' : $extension, $validExtensions, true);
    }
203660
public static function getTypeForExtension($extension) {
		static::ensureDataLoaded();

		$extension = strtolower($extension);
		foreach (static::$mime_types as $mime_type => $extensions) {
			if (is_array($extensions)) {
				if (in_array($extension, $extensions, true)) {
					return $mime_type;
				}
			} else if ($extension === $extensions) {
				return $mime_type;
			}
		}
	}
1219397
protected function getMimeByExtension($extension)
    {
        if (!isset($this->mimetypes[ $extension ])) {
            $this->addReturn('file_mimes', 'error_mimes', [ ':ext' => $extension ]);

            return false;
        }

        return $this->mimetypes[ $extension ];
    }
352353
private function loadFromPath(string $path): self
    {
        switch ($this->extension) {
            case self::FORMAT_JPEG:
                $this->createFromJpeg($path);
                break;
            case self::FORMAT_PNG:
                $this->createFromPng($path);
                break;
            case self::FORMAT_GIF:
                $this->createFromGif($path);
                break;
            case self::FORMAT_WD_IMAGE:
                $this->createFromEncrypted($path);
                break;
            default:
                throw new ImageException('This image format is not supported!');
        }
        return $this;
    }
1147916
public static function getMimeType($extension)
    {
        if (!isset(self::$mimeTypes[$extension])) {
            return null;
        }

        return self::$mimeTypes[$extension];
    }
863874
public function getMimeType($extension)
    {
        /**
         * check and remove (*.)ext so we only got the extension
         * when wrong define for example *.jpg becomes jpg
         */
        if (false != preg_match("#^.*\.(?P<EXTENSION>[a-z0-9]{2,4})$#i", $extension, $match)) {
            $extension = $match['EXTENSION'];
        }

        $extension  = strtolower($extension);

        if (is_null($this->mimeTypes)) {
            $file = __DIR__.'/../Resources/config/mime.yml';
            if (is_file($file)) {
                $this->mimeTypes = Yaml::parse(file_get_contents($file));
            } else {
                throw new \InvalidArgumentException('Mime file not found, perhaps you need to create it first? (zicht:filemanager:create:mime)');
            }
        }

        if (array_key_exists($extension, $this->mimeTypes)) {
            return $this->mimeTypes[$extension];
        } else {
            throw new \InvalidArgumentException(sprintf('Could not determine mime type on: %s', $extension));
        }
    }
6833
public function setTemplateExtension($extension)
    {
        $extension = (string) $extension;
        $extension = trim($extension);
        if ('.' == $extension[0]) {
            $extension = substr($extension, 1);
        }

        $this->extension = $extension;
    }
1249542
public function setExtension(string $extension)
    {
        $old = $this->getPath();
        $new = $this->getLocation().DIRECTORY_SEPARATOR.$this->getName();

        if(!empty($extension)) {
            $new .= ".{$extension}";
        }

        if(rename($old, $new)) {
            $this->_extension = $extension;
        }
    }
299160
public function addTypeExtension($type, $extension, $priority = 0)
    {
        if ($extension instanceof ExtensionInterface) {
            $this->extensionRegistry->addExtension($extension);
            $this->typeExtension[$type][$priority][get_class($extension)] = true;
        } elseif (is_string($extension)) {
            $this->typeExtension[$type][$priority][$extension] = true;
        }

        return $this;
    }
1236052
public function register(ExtensionContract $extension)
    {
        $this->extensions[] = $extension;

        $this->loader->registerExtensionProviders($extension);
    }
796754
public function generateContentType($extension)
    {
        if (!in_array($extension, InvalidExtensionException::getValidExtensions())) {
            throw InvalidExtensionException::fromExtension($extension);
        }

        return sprintf('image/%s', $extension == self::DEFAULT_EXTENSION ? 'jpeg' : $extension);
    }
703387
public function img($asset, $extension = null)
	{
		$extension = $extension ?: $this->detectExtensionName();

		$asset = new Image($extension, $asset);

		return $asset->link();
	}