mirror of
https://github.com/Intervention/image.git
synced 2025-08-19 12:11:26 +02:00
Animaton loops
This commit is contained in:
@@ -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());
|
||||
|
@@ -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)));
|
||||
}
|
||||
|
@@ -14,6 +14,8 @@ use IteratorAggregate;
|
||||
|
||||
class Image extends AbstractImage implements ImageInterface, IteratorAggregate
|
||||
{
|
||||
protected $loops = 0;
|
||||
|
||||
public function __construct(protected Collection $frames)
|
||||
{
|
||||
//
|
||||
|
@@ -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));
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user