Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix thumbnail allow_upscale option #616

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Imagine/Filter/Loader/ThumbnailFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Liip\ImagineBundle\Imagine\Filter\Loader;

use Imagine\Filter\Basic\Thumbnail;
use Imagine\Filter\Basic\Resize;
use Imagine\Image\Box;
use Imagine\Image\ImageInterface;

Expand Down Expand Up @@ -42,6 +43,12 @@ public function load(ImageInterface $image, array $options = array())
if (($origWidth > $width || $origHeight > $height)
|| (!empty($options['allow_upscale']) && ($origWidth !== $width || $origHeight !== $height))
) {
if(($origWidth < $width || $origHeight < $height)){
// resize first
$ratio = max($width / $origWidth, $height / $origHeight);
$resizeFilter = new Resize(new Box(round($origWidth * $ratio), round($origHeight * $ratio)));
$image = $resizeFilter->apply($image);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicate code. Why not just do:

$upscale = new UpscaleFilterLoader;
$image = $upscale->load($image, array('min' => array($width, $height));

See https://github.com/liip/LiipImagineBundle/blob/master/Imagine/Filter/Loader/UpscaleFilterLoader.php

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cab you bake this into a PR of your own?

$filter = new Thumbnail(new Box($width, $height), $mode, $filter);
$image = $filter->apply($image);
}
Expand Down