forked from liip/LiipImagineBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request liip#248 from maximecolin/master
Add Upscale filter
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Liip\ImagineBundle\Imagine\Filter\Loader; | ||
|
||
use Imagine\Filter\Basic\Resize; | ||
use Imagine\Image\ImageInterface; | ||
use Imagine\Image\Box; | ||
use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface; | ||
|
||
/** | ||
* Upscale filter | ||
* | ||
* @author Maxime Colin <[email protected]> | ||
*/ | ||
class UpscaleFilterLoader implements LoaderInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function load(ImageInterface $image, array $options = array()) | ||
{ | ||
if (!isset($options['min'])) { | ||
throw new InvalidArgumentException('Missing min option.'); | ||
} | ||
|
||
list($width, $height) = $options['min']; | ||
|
||
$size = $image->getSize(); | ||
$origWidth = $size->getWidth(); | ||
$origHeight = $size->getHeight(); | ||
|
||
if ($origWidth < $width || $origHeight < $height) { | ||
|
||
$widthRatio = $width / $origWidth ; | ||
$heightRatio = $height / $origHeight; | ||
|
||
$ratio = $widthRatio > $heightRatio ? $widthRatio : $heightRatio; | ||
|
||
$filter = new Resize(new Box($origWidth * $ratio, $origHeight * $ratio)); | ||
|
||
return $filter->apply($image); | ||
} | ||
|
||
return $image; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters