From a4f7d8ab506fc9c5113ce12c98a1101ee7fc8642 Mon Sep 17 00:00:00 2001 From: Gregoire Humeau Date: Wed, 7 Oct 2015 11:36:55 +0200 Subject: [PATCH 1/6] Implement Imagine Grayscale filter --- .../Filter/Loader/GrayscaleFilterLoader.php | 24 +++++++++++++++++++ Resources/config/imagine.xml | 5 ++++ 2 files changed, 29 insertions(+) create mode 100644 Imagine/Filter/Loader/GrayscaleFilterLoader.php diff --git a/Imagine/Filter/Loader/GrayscaleFilterLoader.php b/Imagine/Filter/Loader/GrayscaleFilterLoader.php new file mode 100644 index 000000000..665813e52 --- /dev/null +++ b/Imagine/Filter/Loader/GrayscaleFilterLoader.php @@ -0,0 +1,24 @@ + + */ +class GrayscaleFilterLoader implements LoaderInterface +{ + /** + * {@inheritdoc} + */ + public function load(ImageInterface $image, array $options = []) + { + $filter = new Grayscale(); + + return $filter->apply($image); + } +} \ No newline at end of file diff --git a/Resources/config/imagine.xml b/Resources/config/imagine.xml index dc4928539..620b7c8a7 100644 --- a/Resources/config/imagine.xml +++ b/Resources/config/imagine.xml @@ -35,6 +35,7 @@ Liip\ImagineBundle\Imagine\Filter\Loader\ResizeFilterLoader Liip\ImagineBundle\Imagine\Filter\Loader\ThumbnailFilterLoader Liip\ImagineBundle\Imagine\Filter\Loader\CropFilterLoader + Liip\ImagineBundle\Imagine\Filter\Loader\GrayscaleFilterLoader Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader Liip\ImagineBundle\Imagine\Filter\Loader\WatermarkFilterLoader Liip\ImagineBundle\Imagine\Filter\Loader\StripFilterLoader @@ -152,6 +153,10 @@ + + + + From a9c29de189264bfbdde3dc786fcf3c4a3fcaf655 Mon Sep 17 00:00:00 2001 From: Gregoire Humeau Date: Wed, 7 Oct 2015 11:37:32 +0200 Subject: [PATCH 2/6] Add phpunit tests for Grayscale filter --- .../Loader/GrayscaleFilterLoaderTest.php | 21 +++++++++++ .../Loader/GrayscaleFilterLoaderTest.php | 36 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php create mode 100644 Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php diff --git a/Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php b/Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php new file mode 100644 index 000000000..cfac2c07c --- /dev/null +++ b/Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php @@ -0,0 +1,21 @@ + + */ +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); + } +} diff --git a/Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php new file mode 100644 index 000000000..19c646cc1 --- /dev/null +++ b/Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php @@ -0,0 +1,36 @@ + + */ +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); + } +} From 23dafeb0bc8d935d170e7aa3afe0d807b0a179fe Mon Sep 17 00:00:00 2001 From: Gregoire Humeau Date: Wed, 7 Oct 2015 14:16:55 +0200 Subject: [PATCH 3/6] Change array definition for PHP 5.3 support --- Imagine/Filter/Loader/GrayscaleFilterLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Imagine/Filter/Loader/GrayscaleFilterLoader.php b/Imagine/Filter/Loader/GrayscaleFilterLoader.php index 665813e52..de153fb55 100644 --- a/Imagine/Filter/Loader/GrayscaleFilterLoader.php +++ b/Imagine/Filter/Loader/GrayscaleFilterLoader.php @@ -15,7 +15,7 @@ class GrayscaleFilterLoader implements LoaderInterface /** * {@inheritdoc} */ - public function load(ImageInterface $image, array $options = []) + public function load(ImageInterface $image, array $options = array()) { $filter = new Grayscale(); From 81912759985b4f08c89f7579f1866ee21e15a0ba Mon Sep 17 00:00:00 2001 From: Gregoire Humeau Date: Mon, 4 Jan 2016 17:05:12 +0100 Subject: [PATCH 4/6] Add documentation for Grayscale filter --- Resources/doc/filters.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Resources/doc/filters.rst b/Resources/doc/filters.rst index 60a516614..23bcf71b9 100644 --- a/Resources/doc/filters.rst +++ b/Resources/doc/filters.rst @@ -226,6 +226,19 @@ It modifies the way the image is loaded progressively: # mode can be one of: 'none', 'line', 'plane' and 'partition' mode: line +The ``grayscale`` filter +~~~~~~~~~~~~~~~~~~~~~~~~ + +It modifies the image colors by calculating the gray-value based on RGB: + +.. code-block:: yaml + + liip_imagine: + filter_sets: + my_thumb: + filters: + grayscale: ~ + Load your Custom Filters ------------------------ From ff4b097a5067192ab933acde4f70224b75413380 Mon Sep 17 00:00:00 2001 From: Gregoire Humeau Date: Tue, 5 Jan 2016 16:52:17 +0100 Subject: [PATCH 5/6] Style CI --- Imagine/Filter/Loader/GrayscaleFilterLoader.php | 4 ++-- .../Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php | 2 +- Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Imagine/Filter/Loader/GrayscaleFilterLoader.php b/Imagine/Filter/Loader/GrayscaleFilterLoader.php index de153fb55..5c4d3bce0 100644 --- a/Imagine/Filter/Loader/GrayscaleFilterLoader.php +++ b/Imagine/Filter/Loader/GrayscaleFilterLoader.php @@ -6,7 +6,7 @@ use Imagine\Image\ImageInterface; /** - * GrayscaleFilterLoader - apply grayscale filter + * GrayscaleFilterLoader - apply grayscale filter. * * @author Gregoire Humeau */ @@ -21,4 +21,4 @@ public function load(ImageInterface $image, array $options = array()) return $filter->apply($image); } -} \ No newline at end of file +} diff --git a/Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php b/Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php index cfac2c07c..178cf614d 100644 --- a/Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php +++ b/Tests/Functional/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php @@ -5,7 +5,7 @@ use Liip\ImagineBundle\Tests\Functional\WebTestCase; /** - * Functional test cases for GrayscaleFilterLoader class + * Functional test cases for GrayscaleFilterLoader class. * * @author Gregoire Humeau */ diff --git a/Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php b/Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php index 19c646cc1..b9cad8c42 100644 --- a/Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php +++ b/Tests/Imagine/Filter/Loader/GrayscaleFilterLoaderTest.php @@ -10,9 +10,10 @@ use Liip\ImagineBundle\Tests\AbstractTest; /** - * Test cases for GrayscaleFilterLoader class + * Test cases for GrayscaleFilterLoader class. * * @covers Liip\ImagineBundle\Imagine\Filter\Loader\GrayscaleFilterLoader + * * @author Gregoire Humeau */ class GrayscaleFilterLoaderTest extends AbstractTest @@ -31,6 +32,6 @@ public function testLoadGrayscale() //Test result $pixel = $result->getColorAt(new Point(10, 10)); - $this->assertEquals('#565656', (string)$pixel); + $this->assertEquals('#565656', (string) $pixel); } } From c2062125040088e9cdef62a4c630d847e41f3b0d Mon Sep 17 00:00:00 2001 From: Gregoire Humeau Date: Tue, 5 Jan 2016 17:53:09 +0100 Subject: [PATCH 6/6] Upgrade Imagine lowest dependency from 0.5 to 0.6.3 for Grayscale filter results purpose --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fedaef89a..0ba41284e 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require": { "php": "^5.3.9|^7.0", - "imagine/Imagine": "~0.5,<0.7", + "imagine/Imagine": "^0.6.3,<0.7", "symfony/finder": "~2.3|~3.0", "symfony/filesystem": "~2.3|~3.0", "symfony/options-resolver": "~2.3|~3.0",