1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-21 13:11:18 +02:00

Animaton loops

This commit is contained in:
Oliver Vogel
2021-10-21 16:55:03 +02:00
parent 60f7b300c4
commit 5881789549
5 changed files with 21 additions and 0 deletions

View File

@@ -17,6 +17,8 @@ abstract class AbstractImage
{ {
use CanResolveDriverClass; use CanResolveDriverClass;
protected $loops = 0;
public function getIterator(): Collection public function getIterator(): Collection
{ {
return $this->frames; return $this->frames;
@@ -34,6 +36,18 @@ abstract class AbstractImage
return $this; return $this;
} }
public function setLoops(int $count): ImageInterface
{
$this->loops = $count;
return $this;
}
public function loops(): int
{
return $this->loops;
}
public function size(): SizeInterface public function size(): SizeInterface
{ {
return new Size($this->width(), $this->height()); return new Size($this->width(), $this->height());

View File

@@ -40,6 +40,8 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
$image = new Image(new Collection()); $image = new Image(new Collection());
$gif = GifDecoder::decode($input); $gif = GifDecoder::decode($input);
$image->setLoops($gif->getMainApplicationExtension()?->getLoops());
if (!$gif->isAnimated()) { if (!$gif->isAnimated()) {
return $image->addFrame(new Frame(@imagecreatefromstring($input))); return $image->addFrame(new Frame(@imagecreatefromstring($input)));
} }

View File

@@ -14,6 +14,8 @@ use IteratorAggregate;
class Image extends AbstractImage implements ImageInterface, IteratorAggregate class Image extends AbstractImage implements ImageInterface, IteratorAggregate
{ {
protected $loops = 0;
public function __construct(protected Collection $frames) public function __construct(protected Collection $frames)
{ {
// //

View File

@@ -24,6 +24,7 @@ class BinaryImageDecoder extends AbstractDecoder implements DecoderInterface
$imagick = $imagick->coalesceImages(); $imagick = $imagick->coalesceImages();
$image = new Image(new Collection()); $image = new Image(new Collection());
$image->setLoops($imagick->getNumberImages());
foreach ($imagick as $frame_content) { foreach ($imagick as $frame_content) {
$image->addFrame(new Frame($frame_content)); $image->addFrame(new Frame($frame_content));

View File

@@ -12,4 +12,6 @@ interface ImageInterface
public function isAnimated(): bool; public function isAnimated(): bool;
public function greyscale(): ImageInterface; public function greyscale(): ImageInterface;
public function encode(EncoderInterface $encoder): EncodedImage; public function encode(EncoderInterface $encoder): EncodedImage;
public function setLoops(int $count): ImageInterface;
public function loops(): int;
} }