Skip to content

Instantly share code, notes, and snippets.

@avalanche123
Created October 13, 2011 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avalanche123/1283731 to your computer and use it in GitHub Desktop.
Save avalanche123/1283731 to your computer and use it in GitHub Desktop.
Reflection filter in Imagine
<?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