1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-19 12:11:26 +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;
protected $loops = 0;
public function getIterator(): Collection
{
return $this->frames;
@@ -34,6 +36,18 @@ abstract class AbstractImage
return $this;
}
public function setLoops(int $count): ImageInterface
{
$this->loops = $count;
return $this;
}
public function loops(): int
{
return $this->loops;
}
public function size(): SizeInterface
{
return new Size($this->width(), $this->height());

View File

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

View File

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

View File

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

View File

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