mirror of
https://github.com/Intervention/image.git
synced 2025-08-29 16:50:07 +02:00
Added modifiers to mirror images horizontally & vertically
This commit is contained in:
@@ -153,6 +153,30 @@ abstract class AbstractImage
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a vertical mirror image
|
||||||
|
*
|
||||||
|
* @return ImageInterface
|
||||||
|
*/
|
||||||
|
public function flip(): ImageInterface
|
||||||
|
{
|
||||||
|
return $this->modify(
|
||||||
|
$this->resolveDriverClass('Modifiers\FlipModifier')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a horizontal mirror image
|
||||||
|
*
|
||||||
|
* @return ImageInterface
|
||||||
|
*/
|
||||||
|
public function flop(): ImageInterface
|
||||||
|
{
|
||||||
|
return $this->modify(
|
||||||
|
$this->resolveDriverClass('Modifiers\FlopModifier')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function place($element, string $position = 'top-left', int $offset_x = 0, int $offset_y = 0): ImageInterface
|
public function place($element, string $position = 'top-left', int $offset_x = 0, int $offset_y = 0): ImageInterface
|
||||||
{
|
{
|
||||||
return $this->modify(
|
return $this->modify(
|
||||||
|
18
src/Drivers/Gd/Modifiers/FlipModifier.php
Normal file
18
src/Drivers/Gd/Modifiers/FlipModifier.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
|
class FlipModifier implements ModifierInterface
|
||||||
|
{
|
||||||
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
|
{
|
||||||
|
foreach ($image as $frame) {
|
||||||
|
imageflip($frame->getCore(), IMG_FLIP_VERTICAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
}
|
18
src/Drivers/Gd/Modifiers/FlopModifier.php
Normal file
18
src/Drivers/Gd/Modifiers/FlopModifier.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
|
class FlopModifier implements ModifierInterface
|
||||||
|
{
|
||||||
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
|
{
|
||||||
|
foreach ($image as $frame) {
|
||||||
|
imageflip($frame->getCore(), IMG_FLIP_HORIZONTAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
}
|
18
src/Drivers/Imagick/Modifiers/FlipModifier.php
Normal file
18
src/Drivers/Imagick/Modifiers/FlipModifier.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
||||||
|
|
||||||
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
|
class FlipModifier implements ModifierInterface
|
||||||
|
{
|
||||||
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
|
{
|
||||||
|
foreach ($image as $frame) {
|
||||||
|
$frame->getCore()->flipImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
}
|
18
src/Drivers/Imagick/Modifiers/FlopModifier.php
Normal file
18
src/Drivers/Imagick/Modifiers/FlopModifier.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
||||||
|
|
||||||
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
|
||||||
|
class FlopModifier implements ModifierInterface
|
||||||
|
{
|
||||||
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
|
{
|
||||||
|
foreach ($image as $frame) {
|
||||||
|
$frame->getCore()->flopImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $image;
|
||||||
|
}
|
||||||
|
}
|
34
tests/Drivers/Gd/Modifiers/FlipFlopModifierTest.php
Normal file
34
tests/Drivers/Gd/Modifiers/FlipFlopModifierTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intervention\Image\Tests\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
|
use Intervention\Image\Drivers\Gd\Modifiers\FlipModifier;
|
||||||
|
use Intervention\Image\Drivers\Gd\Modifiers\FlopModifier;
|
||||||
|
use Intervention\Image\Tests\TestCase;
|
||||||
|
use Intervention\Image\Tests\Traits\CanCreateGdTestImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires extension gd
|
||||||
|
* @covers \Intervention\Image\Drivers\Gd\Modifiers\FlipModifier
|
||||||
|
* @covers \Intervention\Image\Drivers\Gd\Modifiers\FlopModifier
|
||||||
|
*/
|
||||||
|
class FlipFlopModifierTest extends TestCase
|
||||||
|
{
|
||||||
|
use CanCreateGdTestImage;
|
||||||
|
|
||||||
|
public function testFlipImage(): void
|
||||||
|
{
|
||||||
|
$image = $this->createTestImage('tile.png');
|
||||||
|
$this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex());
|
||||||
|
$image->modify(new FlipModifier());
|
||||||
|
$this->assertEquals('000000', $image->pickColor(0, 0)->toHex());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFlopImage(): void
|
||||||
|
{
|
||||||
|
$image = $this->createTestImage('tile.png');
|
||||||
|
$this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex());
|
||||||
|
$image->modify(new FlopModifier());
|
||||||
|
$this->assertEquals('000000', $image->pickColor(0, 0)->toHex());
|
||||||
|
}
|
||||||
|
}
|
34
tests/Drivers/Imagick/Modifiers/FlipFlopModifierTest.php
Normal file
34
tests/Drivers/Imagick/Modifiers/FlipFlopModifierTest.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Intervention\Image\Tests\Drivers\Imagick\Modifiers;
|
||||||
|
|
||||||
|
use Intervention\Image\Drivers\Imagick\Modifiers\FlipModifier;
|
||||||
|
use Intervention\Image\Drivers\Imagick\Modifiers\FlopModifier;
|
||||||
|
use Intervention\Image\Tests\TestCase;
|
||||||
|
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires extension imagick
|
||||||
|
* @covers \Intervention\Image\Drivers\Imagick\Modifiers\FlipModifier
|
||||||
|
* @covers \Intervention\Image\Drivers\Imagick\Modifiers\FlopModifier
|
||||||
|
*/
|
||||||
|
class FlipFlopModifierTest extends TestCase
|
||||||
|
{
|
||||||
|
use CanCreateImagickTestImage;
|
||||||
|
|
||||||
|
public function testFlipImage(): void
|
||||||
|
{
|
||||||
|
$image = $this->createTestImage('tile.png');
|
||||||
|
$this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex());
|
||||||
|
$image->modify(new FlipModifier());
|
||||||
|
$this->assertEquals('000000', $image->pickColor(0, 0)->toHex());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFlopImage(): void
|
||||||
|
{
|
||||||
|
$image = $this->createTestImage('tile.png');
|
||||||
|
$this->assertEquals('b4e000', $image->pickColor(0, 0)->toHex());
|
||||||
|
$image->modify(new FlopModifier());
|
||||||
|
$this->assertEquals('000000', $image->pickColor(0, 0)->toHex());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user