Skip to content

Instantly share code, notes, and snippets.

@gwoo
Created June 30, 2012 17:41
Show Gist options
  • Save gwoo/3024797 to your computer and use it in GitHub Desktop.
Save gwoo/3024797 to your computer and use it in GitHub Desktop.
ReflectionFilter
<?php
namespace moneygram\extensions\imagine;
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