Created
October 13, 2011 08:26
-
-
Save avalanche123/1283731 to your computer and use it in GitHub Desktop.
Reflection filter in Imagine
This file contains hidden or 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
<?php | |
class ReflectionFilter implements Imagine\Filter\FilterInterface | |
{ | |
private $imagine; | |
public function __construct(Imagine\Image\ImagineInterface $imagine) | |
{ | |
$this->imagine = $imagine; | |
} | |
public function apply(Imagine\Image\ImageInterface $image) | |
{ | |
$size = $image->getSize(); | |
$canvas = new Imagine\Image\Box($size->getWidth(), $size->getHeight() * 2); | |
$reflection = $image->copy() | |
->flipVertically() | |
->applyMask($this->getTransparencyMask($size)) | |
; | |
return $this->imagine->create($canvas, new Imagine\Image\Color('fff', 100)) | |
->paste($image, new Imagine\Image\Point(0, 0)) | |
->paste($reflection, new Imagine\Image\Point(0, $size->getHeight())); | |
} | |
private function getTransparencyMask(Imagine\Image\BoxInterface $size) | |
{ | |
$white = new Imagine\Image\Color('fff'); | |
$fill = new Imagine\Image\Fill\Gradient\Vertical( | |
$size->getHeight(), | |
$white->darken(127), | |
$white | |
); | |
return $this->imagine->create($size) | |
->fill($fill) | |
; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment