mirror of
https://github.com/Intervention/image.git
synced 2025-08-12 00:43:59 +02:00
Fix bug in RemoveAnimationModifiers
This commit is contained in:
@@ -27,6 +27,18 @@ class Image extends AbstractImage implements ImageInterface, IteratorAggregate
|
||||
//
|
||||
}
|
||||
|
||||
public function frames(): Collection
|
||||
{
|
||||
return $this->frames;
|
||||
}
|
||||
|
||||
public function setFrames(Collection $frames): ImageInterface
|
||||
{
|
||||
$this->frames = $frames;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
return $this->frames;
|
||||
|
@@ -7,9 +7,12 @@ use Intervention\Image\Drivers\Gd\Image;
|
||||
use Intervention\Image\Exceptions\RuntimeException;
|
||||
use Intervention\Image\Interfaces\ImageInterface;
|
||||
use Intervention\Image\Interfaces\ModifierInterface;
|
||||
use Intervention\Image\Traits\CanCheckType;
|
||||
|
||||
class RemoveAnimationModifier implements ModifierInterface
|
||||
{
|
||||
use CanCheckType;
|
||||
|
||||
public function __construct(protected int $position = 0)
|
||||
{
|
||||
//
|
||||
@@ -21,6 +24,8 @@ class RemoveAnimationModifier implements ModifierInterface
|
||||
throw new RuntimeException('Image is not animated.');
|
||||
}
|
||||
|
||||
$image = $this->failIfNotClass($image, Image::class);
|
||||
|
||||
$frames = new Collection();
|
||||
foreach ($image as $key => $frame) {
|
||||
if ($this->position == $key) {
|
||||
@@ -28,6 +33,6 @@ class RemoveAnimationModifier implements ModifierInterface
|
||||
}
|
||||
}
|
||||
|
||||
return new Image($frames);
|
||||
return $image->setFrames($frames);
|
||||
}
|
||||
}
|
||||
|
@@ -39,6 +39,13 @@ class Image extends AbstractImage implements ImageInterface, Iterator
|
||||
return $this->imagick;
|
||||
}
|
||||
|
||||
public function setImagick(Imagick $imagick): ImageInterface
|
||||
{
|
||||
$this->imagick = $imagick;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function frame(int $position = 0): FrameInterface
|
||||
{
|
||||
foreach ($this->imagick as $core) {
|
||||
|
@@ -3,13 +3,16 @@
|
||||
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;
|
||||
use Intervention\Image\Drivers\Imagick\Image;
|
||||
use Intervention\Image\Traits\CanCheckType;
|
||||
|
||||
class RemoveAnimationModifier implements ModifierInterface
|
||||
{
|
||||
use CanCheckType;
|
||||
|
||||
public function __construct(protected int $position = 0)
|
||||
{
|
||||
//
|
||||
@@ -21,15 +24,16 @@ class RemoveAnimationModifier implements ModifierInterface
|
||||
throw new RuntimeException('Image is not animated.');
|
||||
}
|
||||
|
||||
$image = $this->failIfNotClass($image, Image::class);
|
||||
|
||||
// create new imagick with just one image
|
||||
$imagick = new Imagick();
|
||||
foreach ($image as $frame) {
|
||||
if ($frame->core()->getIteratorIndex() == $this->position) {
|
||||
$imagick->addImage($frame->core()->getImage());
|
||||
foreach ($image->getImagick() as $key => $core) {
|
||||
if ($key == $this->position) {
|
||||
$imagick->addImage($core->getImage());
|
||||
}
|
||||
}
|
||||
|
||||
$image->destroy();
|
||||
|
||||
return new Image($imagick);
|
||||
return $image->setImagick($imagick);
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,8 @@ class RemoveAnimationModifierTest extends TestCase
|
||||
{
|
||||
$image = $this->createTestImage('animation.gif');
|
||||
$this->assertEquals(8, count($image));
|
||||
$image = $image->modify(new RemoveAnimationModifier(2));
|
||||
$result = $image->modify(new RemoveAnimationModifier(2));
|
||||
$this->assertEquals(1, count($image));
|
||||
$this->assertEquals(1, count($result));
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,8 @@ class RemoveAnimationModifierTest extends TestCase
|
||||
{
|
||||
$image = $this->createTestImage('animation.gif');
|
||||
$this->assertEquals(8, count($image));
|
||||
$image = $image->modify(new RemoveAnimationModifier(2));
|
||||
$result = $image->modify(new RemoveAnimationModifier(2));
|
||||
$this->assertEquals(1, count($image));
|
||||
$this->assertEquals(1, count($result));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user