-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7577986
commit 635567e
Showing
7 changed files
with
137 additions
and
5 deletions.
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
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,35 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Drivers\Gd\Modifiers; | ||
|
||
use Intervention\Image\Collection; | ||
use Intervention\Image\Drivers\Gd\Image; | ||
use Intervention\Image\Exceptions\RuntimeException; | ||
use Intervention\Image\Interfaces\ImageInterface; | ||
use Intervention\Image\Interfaces\ModifierInterface; | ||
|
||
class RemoveAnimationModifier implements ModifierInterface | ||
{ | ||
public function __construct(protected int $position = 0) | ||
{ | ||
// | ||
} | ||
|
||
public function apply(ImageInterface $image): ImageInterface | ||
{ | ||
if (!$image->isAnimated()) { | ||
throw new RuntimeException('Image is not animated.'); | ||
} | ||
|
||
$frames = new Collection(); | ||
foreach ($image as $key => $frame) { | ||
if ($this->position == $key) { | ||
$frames->push($frame); | ||
} else { | ||
imagedestroy($frame->getCore()); | ||
} | ||
} | ||
|
||
return new Image($frames); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Drivers\Imagick\Modifiers; | ||
|
||
use Imagick; | ||
use Intervention\Image\Drivers\Imagick\Image; | ||
use Intervention\Image\Exceptions\RuntimeException; | ||
use Intervention\Image\Interfaces\ImageInterface; | ||
use Intervention\Image\Interfaces\ModifierInterface; | ||
|
||
class RemoveAnimationModifier implements ModifierInterface | ||
{ | ||
public function __construct(protected int $position = 0) | ||
{ | ||
// | ||
} | ||
|
||
public function apply(ImageInterface $image): ImageInterface | ||
{ | ||
if (!$image->isAnimated()) { | ||
throw new RuntimeException('Image is not animated.'); | ||
} | ||
|
||
$imagick = new Imagick(); | ||
foreach ($image as $frame) { | ||
if ($frame->getCore()->getIteratorIndex() == $this->position) { | ||
$imagick->addImage($frame->getCore()->getImage()); | ||
} | ||
} | ||
|
||
$image->destroy(); | ||
|
||
return new Image($imagick); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
tests/Drivers/Gd/Modifiers/RemoveAnimationModifierTest.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,24 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Tests\Drivers\Gd\Modifiers; | ||
|
||
use Intervention\Image\Drivers\Gd\Modifiers\RemoveAnimationModifier; | ||
use Intervention\Image\Tests\TestCase; | ||
use Intervention\Image\Tests\Traits\CanCreateGdTestImage; | ||
|
||
/** | ||
* @requires extension gd | ||
* @covers \Intervention\Image\Drivers\Gd\Modifiers\RemoveAnimationModifier | ||
*/ | ||
class RemoveAnimationModifierTest extends TestCase | ||
{ | ||
use CanCreateGdTestImage; | ||
|
||
public function testApply(): void | ||
{ | ||
$image = $this->createTestImage('animation.gif'); | ||
$this->assertEquals(8, count($image)); | ||
$image = $image->modify(new RemoveAnimationModifier(2)); | ||
$this->assertEquals(1, count($image)); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
tests/Drivers/Imagick/Modifiers/RemoveAnimationModifierTest.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,24 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Tests\Drivers\Imagick\Modifiers; | ||
|
||
use Intervention\Image\Drivers\Imagick\Modifiers\RemoveAnimationModifier; | ||
use Intervention\Image\Tests\TestCase; | ||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage; | ||
|
||
/** | ||
* @requires extension imagick | ||
* @covers \Intervention\Image\Drivers\Imagick\Modifiers\RemoveAnimationModifier | ||
*/ | ||
class RemoveAnimationModifierTest extends TestCase | ||
{ | ||
use CanCreateImagickTestImage; | ||
|
||
public function testApply(): void | ||
{ | ||
$image = $this->createTestImage('animation.gif'); | ||
$this->assertEquals(8, count($image)); | ||
$image = $image->modify(new RemoveAnimationModifier(2)); | ||
$this->assertEquals(1, count($image)); | ||
} | ||
} |