public function scale(\SplFileInfo $source, ThumbnailConfiguration $size, \SplFileInfo $target)
    {
        $img = $this->imagine->open($source->getPathname());

        if ($size->getThumbnail()) {
            $thumb = $this->makeThumbnail($img, $size->getSize());
            $thumb->save($target->getPathname());
        } else {
            $newSize  = $size->getSize();
            $origSize = $img->getSize();
            $factor   = min(
                $newSize->getWidth() / $origSize->getWidth(),
                $newSize->getHeight() / $origSize->getHeight()
            );
            if (!$size->getExact()) {
                // Do not upscale.
                $factor = min(1, $factor);
            }
            $scaledSize = $origSize->scale($factor);
            $img->resize($scaledSize);
            if ($size->getExact()) {
                // Force image size
                if ($img->palette()->supportsAlpha()) {
                    $palette = new RGB();
                    $color = $palette->color('#000', 0);
                    $bg = $this->imagine->create($newSize, $color);
                } else {
                    $bg = $this->imagine->create($newSize);
                }

                if ($size->getFillbg()) {
                    $this->fillWithBlurredImage($bg, $img);
                }

                $bg->paste(
                    $img,
                    new Point(
                        ($newSize->getWidth() - $scaledSize->getWidth()) / 2,
                        ($newSize->getHeight() - $scaledSize->getHeight()) / 2
                    )
                );
                $bg->save($target->getPathname());
            } else {
                $img->save($target->getPathname());
            }
        }
    }
public function scale(\SplFileInfo $source, ThumbnailConfiguration $size, \SplFileInfo $target)
    {
        $img = $this->imagine->open($source->getPathname());

        if ($size->getThumbnail()) {
            $thumb = $this->makeThumbnail($img, $size->getSize());
            $thumb->save($target->getPathname());
        } else {
            $newSize  = $size->getSize();
            $origSize = $img->getSize();
            $factor   = min(
                $newSize->getWidth() / $origSize->getWidth(),
                $newSize->getHeight() / $origSize->getHeight()
            );
            if (!$size->getExact()) {
                // Do not upscale.
                $factor = min(1, $factor);
            }
            $scaledSize = $origSize->scale($factor);
            $img->resize($scaledSize);
            if ($size->getExact()) {
                // Force image size
                if ($img->palette()->supportsAlpha()) {
                    $palette = new RGB();
                    $color = $palette->color('#000', 0);
                    $bg = $this->imagine->create($newSize, $color);
                } else {
                    $bg = $this->imagine->create($newSize);
                }

                if ($size->getFillbg()) {
                    $this->fillWithBlurredImage($bg, $img);
                }

                $bg->paste(
                    $img,
                    new Point(
                        ($newSize->getWidth() - $scaledSize->getWidth()) / 2,
                        ($newSize->getHeight() - $scaledSize->getHeight()) / 2
                    )
                );
                $bg->save($target->getPathname());
            } else {
                $img->save($target->getPathname());
            }
        }
    }
{@inheritdoc}