Skip to content

Commit bd29f65

Browse files
authored
Merge pull request #221 from BlueBayTravel/flip-manipulator
Flip manipulator
2 parents a6cbd31 + 0de6b4d commit bd29f65

File tree

5 files changed

+109
-1
lines changed

5 files changed

+109
-1
lines changed

docs/1.0/api/flip.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
layout: default
3+
title: Flip
4+
---
5+
6+
# Flip
7+
8+
## Flip `flip`
9+
10+
Flips the image. Accepts `v`, `h` and `both`.
11+
12+
~~~ html
13+
<img src="kayaks.jpg?h=500&flip=v">
14+
~~~
15+
16+
[![© Photo Joel Reynolds](https://glide.herokuapp.com/1.0/kayaks.jpg?h=500&flip=v)](https://glide.herokuapp.com/1.0/kayaks.jpg?h=500&flip=v)

docs/1.0/api/quick-reference.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ title: Quick reference
88
Name | Function | Description |
99
------- | ---------------- | ----------- | ----
1010
Orientation | `or` | Rotates the image. | [info](api/orientation/#orientation-or)
11+
Flip | `flip` | Flip the image. | [info](api/orientation/#flip-flip)
1112
Crop | `crop` | Crops the image to specific dimensions. | [info](api/crop/#crop-crop)
1213
Width | `w` | Sets the width of the image, in pixels. | [info](api/size/#width-w)
1314
Height | `h` | Sets the height of the image, in pixels. | [info](api/size//#height-h)
@@ -31,4 +32,4 @@ Watermark Alpha | `markalpha` | Sets the watermark opacity. | [info](api/waterm
3132
Background | `bg` | Sets the background color of the image. | [info](api/background/#background-bg)
3233
Border | `border` | Add a border to the image. | [info](api/border/#border-border)
3334
Quality | `q` | Defines the quality of the image. | [info](api/encode/#quality-q)
34-
Format | `fm` | Encodes the image to a specific format. | [info](api/encode/#format-fm)
35+
Format | `fm` | Encodes the image to a specific format. | [info](api/encode/#format-fm)

src/Manipulators/Flip.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace League\Glide\Manipulators;
4+
5+
use Intervention\Image\Image;
6+
7+
/**
8+
* @property string $flip
9+
*/
10+
class Flip extends BaseManipulator
11+
{
12+
/**
13+
* Perform flip image manipulation.
14+
* @param Image $image The source image.
15+
* @return Image The manipulated image.
16+
*/
17+
public function run(Image $image)
18+
{
19+
if ($flip = $this->getFlip()) {
20+
if ($flip === 'both') {
21+
return $image->flip('h')->flip('v');
22+
}
23+
24+
return $image->flip($flip);
25+
}
26+
27+
return $image;
28+
}
29+
30+
/**
31+
* Resolve flip.
32+
* @return string The resolved flip.
33+
*/
34+
public function getFlip()
35+
{
36+
if (in_array($this->flip, ['h', 'v', 'both'], true)) {
37+
return $this->flip;
38+
}
39+
}
40+
}

src/ServerFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use League\Glide\Manipulators\Crop;
1717
use League\Glide\Manipulators\Encode;
1818
use League\Glide\Manipulators\Filter;
19+
use League\Glide\Manipulators\Flip;
1920
use League\Glide\Manipulators\Gamma;
2021
use League\Glide\Manipulators\Orientation;
2122
use League\Glide\Manipulators\Pixelate;
@@ -225,6 +226,7 @@ public function getManipulators()
225226
new Gamma(),
226227
new Sharpen(),
227228
new Filter(),
229+
new Flip(),
228230
new Blur(),
229231
new Pixelate(),
230232
new Watermark($this->getWatermarks(), $this->getWatermarksPathPrefix()),

tests/Manipulators/FlipTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace League\Glide\Manipulators;
4+
5+
use Mockery;
6+
7+
class FlipTest extends \PHPUnit_Framework_TestCase
8+
{
9+
private $manipulator;
10+
11+
public function setUp()
12+
{
13+
$this->manipulator = new Flip();
14+
}
15+
16+
public function tearDown()
17+
{
18+
Mockery::close();
19+
}
20+
21+
public function testCreateInstance()
22+
{
23+
$this->assertInstanceOf('League\Glide\Manipulators\Flip', $this->manipulator);
24+
}
25+
26+
public function testRun()
27+
{
28+
$image = Mockery::mock('Intervention\Image\Image', function ($mock) {
29+
$mock->shouldReceive('flip')->andReturn($mock)->with('h')->once();
30+
$mock->shouldReceive('flip')->andReturn($mock)->with('v')->once();
31+
});
32+
33+
$this->assertInstanceOf(
34+
'Intervention\Image\Image',
35+
$this->manipulator->setParams(['flip' => 'h'])->run($image)
36+
);
37+
38+
$this->assertInstanceOf(
39+
'Intervention\Image\Image',
40+
$this->manipulator->setParams(['flip' => 'v'])->run($image)
41+
);
42+
}
43+
44+
public function testGetFlip()
45+
{
46+
$this->assertSame('h', $this->manipulator->setParams(['flip' => 'h'])->getFlip());
47+
$this->assertSame('v', $this->manipulator->setParams(['flip' => 'v'])->getFlip());
48+
}
49+
}

0 commit comments

Comments
 (0)