File tree Expand file tree Collapse file tree 5 files changed +112
-0
lines changed
Functional/Imagine/Filter/Loader Expand file tree Collapse file tree 5 files changed +112
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Liip \ImagineBundle \Imagine \Filter \Loader ;
4+
5+ use Imagine \Image \ImageInterface ;
6+ use Imagine \Image \ManipulatorInterface ;
7+
8+ /**
9+ * Loader for Imagine's basic rotate method
10+ *
11+ * @author Bocharsky Victor <[email protected] > 12+ */
13+ class RotateFilterLoader implements LoaderInterface
14+ {
15+ /**
16+ * Loads and applies a filter on the given image.
17+ *
18+ * @param ImageInterface $image
19+ * @param array $options
20+ *
21+ * @return ManipulatorInterface
22+ */
23+ public function load (ImageInterface $ image , array $ options = array ())
24+ {
25+ $ angle = isset ($ options ['angle ' ]) ? (int ) $ options ['angle ' ] : 0 ;
26+
27+ return 0 === $ angle ? $ image : $ image ->rotate ($ angle );
28+ }
29+ }
Original file line number Diff line number Diff line change 4141 <parameter key =" liip_imagine.filter.loader.background.class" >Liip\ImagineBundle\Imagine\Filter\Loader\BackgroundFilterLoader</parameter >
4242 <parameter key =" liip_imagine.filter.loader.upscale.class" >Liip\ImagineBundle\Imagine\Filter\Loader\UpscaleFilterLoader</parameter >
4343 <parameter key =" liip_imagine.filter.loader.auto_rotate.class" >Liip\ImagineBundle\Imagine\Filter\Loader\AutoRotateFilterLoader</parameter >
44+ <parameter key =" liip_imagine.filter.loader.rotate.class" >Liip\ImagineBundle\Imagine\Filter\Loader\RotateFilterLoader</parameter >
4445 <parameter key =" liip_imagine.filter.loader.interlace.class" >Liip\ImagineBundle\Imagine\Filter\Loader\InterlaceFilterLoader</parameter >
4546
4647 <!-- Data loaders' classes -->
183184 <tag name =" liip_imagine.filter.loader" loader =" auto_rotate" />
184185 </service >
185186
187+ <service id =" liip_imagine.filter.loader.rotate" class =" %liip_imagine.filter.loader.rotate.class%" >
188+ <tag name =" liip_imagine.filter.loader" loader =" rotate" />
189+ </service >
190+
186191 <service id =" liip_imagine.filter.loader.interlace" class =" %liip_imagine.filter.loader.interlace.class%" >
187192 <tag name =" liip_imagine.filter.loader" loader =" interlace" />
188193 </service >
Original file line number Diff line number Diff line change @@ -171,6 +171,20 @@ should be called as early as possible)** Configuration looks like this:
171171 filters :
172172 auto_rotate : ~
173173
174+ The ``rotate `` filter
175+ ~~~~~~~~~~~~~~~~~~~~~
176+
177+ The rotate filter rotates the image based on specified angle (in degrees).
178+ Configuration looks like this:
179+
180+ .. code-block :: yaml
181+
182+ liip_imagine :
183+ filter_sets :
184+ my_thumb :
185+ filters :
186+ rotate : { angle: 90 }
187+
174188 The ``interlace `` filter
175189~~~~~~~~~~~~~~~~~~~~~~~~
176190
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Liip \ImagineBundle \Tests \Functional \Imagine \Filter \Loader ;
4+
5+ use Liip \ImagineBundle \Tests \Functional \WebTestCase ;
6+
7+ /**
8+ * Functional test cases for RotateFilterLoader class
9+ *
10+ * @author Bocharsky Victor <[email protected] > 11+ */
12+ class RotateFilterLoaderTest extends WebTestCase
13+ {
14+ public function testCouldBeGetFromContainerAsService ()
15+ {
16+ $ this ->createClient ();
17+ $ service = self ::$ kernel ->getContainer ()->get ('liip_imagine.filter.loader.rotate ' );
18+
19+ $ this ->assertInstanceOf ('Liip\ImagineBundle\Imagine\Filter\Loader\RotateFilterLoader ' , $ service );
20+ }
21+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Liip \ImagineBundle \Tests \Filter ;
4+
5+ use Liip \ImagineBundle \Imagine \Filter \Loader \RotateFilterLoader ;
6+ use Liip \ImagineBundle \Tests \AbstractTest ;
7+
8+ /**
9+ * Test cases for RotateFilterLoader class
10+ *
11+ * @covers Liip\ImagineBundle\Imagine\Filter\Loader\RotateFilterLoader
12+ * @author Bocharsky Victor <[email protected] > 13+ */
14+ class RotateFilterLoaderTest extends AbstractTest
15+ {
16+ public function testLoadRotate0Degrees ()
17+ {
18+ $ loader = new RotateFilterLoader ();
19+
20+ $ image = $ this ->getMockImage ();
21+
22+ $ result = $ loader ->load ($ image , array ('angle ' => 0 ));
23+ $ this ->assertSame ($ image , $ result );
24+ }
25+
26+ public function testLoadRotate90Degrees ()
27+ {
28+ $ loader = new RotateFilterLoader ();
29+
30+ $ image = $ this ->getMockImage ();
31+ $ rotatedImage = $ this ->getMockImage ();
32+
33+ $ image
34+ ->expects ($ this ->once ())
35+ ->method ('rotate ' )
36+ ->with (90 )
37+ ->willReturn ($ rotatedImage )
38+ ;
39+
40+ $ result = $ loader ->load ($ image , array ('angle ' => 90 ));
41+ $ this ->assertSame ($ rotatedImage , $ result );
42+ }
43+ }
You can’t perform that action at this time.
0 commit comments