Skip to content

Commit

Permalink
Merge pull request #561 from scuben/fix-upscale-size
Browse files Browse the repository at this point in the history
fix upscale size not being calculated correctly
  • Loading branch information
makasim committed Jun 4, 2015
2 parents 24c977c + 17ebc33 commit 1c9ccde
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Imagine/Filter/Loader/UpscaleFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function load(ImageInterface $image, array $options = array())

$ratio = $widthRatio > $heightRatio ? $widthRatio : $heightRatio;

$filter = new Resize(new Box($origWidth * $ratio, $origHeight * $ratio));
$filter = new Resize(new Box(round($origWidth * $ratio), round($origHeight * $ratio)));

return $filter->apply($image);
}
Expand Down
Binary file added Tests/Fixtures/assets/square-50x50.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Liip\ImagineBundle\Tests\Filter;

use Imagine\Gd\Image;
use Imagine\Gd\Imagine;
use Liip\ImagineBundle\Imagine\Filter\Loader\UpscaleFilterLoader;
use Liip\ImagineBundle\Tests\AbstractTest;

/**
* @covers Liip\ImagineBundle\Imagine\Filter\Loader\UpscaleFilterLoader
*
* Due to int casting in Imagine\Image\Box which can lead to wrong pixel
* numbers ( e.g. float(201) casted to int(200) ). Solved by round the
* floating number before passing to the Box constructor.
*/
class FloatToIntCastByRoundUpscaleFilterLoaderTest extends AbstractTest
{
public function testLoad()
{
$loader = new UpscaleFilterLoader();
$imagine = new Imagine();
$image = $imagine->open(__DIR__.'/../../../Fixtures/assets/square-50x50.png');

$options = array(
'min' => array(201, 201),
);

$image = $loader->load($image, $options);
$size = $image->getSize();

$this->assertEquals($options['min'], array($size->getWidth(), $size->getHeight()));
}
}

0 comments on commit 1c9ccde

Please sign in to comment.