public function create($path, $size = null, $targetPath = null): ImageInterface
    {
        if ($path instanceof ImageInterface) {
            $image = $path;
        } else {
            $fileExtension = strtolower(pathinfo($path, PATHINFO_EXTENSION));

            if (\in_array($fileExtension, ['svg', 'svgz'], true)) {
                $imagine = $this->imagineSvg;
            } else {
                $imagine = $this->imagine;
            }

            if (!\in_array($fileExtension, $this->validExtensions, true)) {
                throw new \InvalidArgumentException(
                    sprintf('Image type "%s" was not allowed to be processed', $fileExtension)
                );
            }

            $image = new Image((string) $path, $imagine, $this->filesystem);
        }

        if ($size instanceof ResizeConfigurationInterface) {
            /** @var ResizeConfigurationInterface $resizeConfig */
            $resizeConfig = $size;
            $importantPart = null;
        } else {
            [$resizeConfig, $importantPart] = $this->createConfig($size, $image);
        }

        if (!\is_object($path) || !($path instanceof ImageInterface)) {
            if (null === $importantPart) {
                $importantPart = $this->createImportantPart($image);
            }

            $image->setImportantPart($importantPart);
        }

        if (null === $targetPath && $resizeConfig->isEmpty()) {
            return $image;
        }

        return $this->resizer->resize(
            $image,
            $resizeConfig,
            (new ResizeOptions())
                ->setImagineOptions($this->imagineOptions)
                ->setTargetPath($targetPath)
                ->setBypassCache($this->bypassCache)
        );
    }
public function create($path, $size = null, $targetPath = null): ImageInterface
    {
        if ($path instanceof ImageInterface) {
            $image = $path;
        } else {
            $fileExtension = strtolower(pathinfo($path, PATHINFO_EXTENSION));

            if (\in_array($fileExtension, ['svg', 'svgz'], true)) {
                $imagine = $this->imagineSvg;
            } else {
                $imagine = $this->imagine;
            }

            if (!\in_array($fileExtension, $this->validExtensions, true)) {
                throw new \InvalidArgumentException(
                    sprintf('Image type "%s" was not allowed to be processed', $fileExtension)
                );
            }

            $image = new Image((string) $path, $imagine, $this->filesystem);
        }

        if ($size instanceof ResizeConfigurationInterface) {
            /** @var ResizeConfigurationInterface $resizeConfig */
            $resizeConfig = $size;
            $importantPart = null;
        } else {
            [$resizeConfig, $importantPart] = $this->createConfig($size, $image);
        }

        if (!\is_object($path) || !($path instanceof ImageInterface)) {
            if (null === $importantPart) {
                $importantPart = $this->createImportantPart($image);
            }

            $image->setImportantPart($importantPart);
        }

        if (null === $targetPath && $resizeConfig->isEmpty()) {
            return $image;
        }

        return $this->resizer->resize(
            $image,
            $resizeConfig,
            (new ResizeOptions())
                ->setImagineOptions($this->imagineOptions)
                ->setTargetPath($targetPath)
                ->setBypassCache($this->bypassCache)
        );
    }
{@inheritdoc}