-
Notifications
You must be signed in to change notification settings - Fork 379
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 #638 from gregumo/master
Implement Imagine Grayscale filter
- Loading branch information
Showing
6 changed files
with
101 additions
and
1 deletion.
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,24 @@ | ||
<?php | ||
|
||
namespace Liip\ImagineBundle\Imagine\Filter\Loader; | ||
|
||
use Imagine\Filter\Advanced\Grayscale; | ||
use Imagine\Image\ImageInterface; | ||
|
||
/** | ||
* GrayscaleFilterLoader - apply grayscale filter. | ||
* | ||
* @author Gregoire Humeau <gregoire.humeau@gmail.com> | ||
*/ | ||
class GrayscaleFilterLoader implements LoaderInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(ImageInterface $image, array $options = array()) | ||
{ | ||
$filter = new Grayscale(); | ||
|
||
return $filter->apply($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
21 changes: 21 additions & 0 deletions
21
Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php
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,21 @@ | ||
<?php | ||
|
||
namespace Liip\ImagineBundle\Tests\Functional\Imagine\Filter\Loader; | ||
|
||
use Liip\ImagineBundle\Tests\Functional\WebTestCase; | ||
|
||
/** | ||
* Functional test cases for GrayscaleFilterLoader class. | ||
* | ||
* @author Gregoire Humeau <gregoire.humeau@gmail.com> | ||
*/ | ||
class GrayscaleFilterLoaderTest extends WebTestCase | ||
{ | ||
public function testCouldBeGetFromContainerAsService() | ||
{ | ||
$this->createClient(); | ||
$service = self::$kernel->getContainer()->get('liip_imagine.filter.loader.grayscale'); | ||
|
||
$this->assertInstanceOf('Liip\ImagineBundle\Imagine\Filter\Loader\GrayscaleFilterLoader', $service); | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace Liip\ImagineBundle\Tests\Filter; | ||
|
||
use Imagine\Image\Box; | ||
use Imagine\Image\Palette\RGB; | ||
use Imagine\Image\Point; | ||
use Imagine\Gd\Imagine; | ||
use Liip\ImagineBundle\Imagine\Filter\Loader\GrayscaleFilterLoader; | ||
use Liip\ImagineBundle\Tests\AbstractTest; | ||
|
||
/** | ||
* Test cases for GrayscaleFilterLoader class. | ||
* | ||
* @covers Liip\ImagineBundle\Imagine\Filter\Loader\GrayscaleFilterLoader | ||
* | ||
* @author Gregoire Humeau <gregoire.humeau@gmail.com> | ||
*/ | ||
class GrayscaleFilterLoaderTest extends AbstractTest | ||
{ | ||
public function testLoadGrayscale() | ||
{ | ||
$loader = new GrayscaleFilterLoader(); | ||
$palette = new RGB(); | ||
$imagine = new Imagine(); | ||
|
||
// Generate blue image | ||
$image = $imagine->create(new Box(20, 20), $palette->color(array(20, 90, 240))); | ||
|
||
//Apply Grayscale filter | ||
$result = $loader->load($image); | ||
|
||
//Test result | ||
$pixel = $result->getColorAt(new Point(10, 10)); | ||
$this->assertEquals('#565656', (string) $pixel); | ||
} | ||
} |
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