diff --git a/src/Gmagick/Layers.php b/src/Gmagick/Layers.php index 3fc31cb71..706175ca0 100644 --- a/src/Gmagick/Layers.php +++ b/src/Gmagick/Layers.php @@ -108,8 +108,8 @@ public function coalesce() public function animate($format, $delay, $loops) { $formatInfo = Format::get($format); - if ($formatInfo === null || $formatInfo->getID() !== Format::ID_GIF) { - throw new InvalidArgumentException('Animated picture is currently only supported on gif'); + if ($formatInfo === null || !in_array($formatInfo->getID(), array(Format::ID_GIF, Format::ID_WEBP))) { + throw new InvalidArgumentException('Animated picture is currently only supported on gif and webp'); } if (!is_int($loops) || $loops < 0) { diff --git a/src/Imagick/Layers.php b/src/Imagick/Layers.php index d63e36e63..575671339 100644 --- a/src/Imagick/Layers.php +++ b/src/Imagick/Layers.php @@ -92,8 +92,8 @@ public function merge() public function animate($format, $delay, $loops) { $formatInfo = Format::get($format); - if ($formatInfo === null || $formatInfo->getID() !== Format::ID_GIF) { - throw new InvalidArgumentException('Animated picture is currently only supported on gif'); + if ($formatInfo === null || !in_array($formatInfo->getID(), array(Format::ID_GIF, Format::ID_WEBP))) { + throw new InvalidArgumentException('Animated picture is currently only supported on gif and webp'); } if (!is_int($loops) || $loops < 0) { @@ -107,7 +107,7 @@ public function animate($format, $delay, $loops) try { foreach ($this as $offset => $layer) { $this->resource->setIteratorIndex($offset); - $this->resource->setFormat(Format::ID_GIF); + $this->resource->setFormat($formatInfo->getID()); if ($delay !== null) { $layer->getImagick()->setImageDelay($delay / 10); diff --git a/tests/tests/Gmagick/LayersTest.php b/tests/tests/Gmagick/LayersTest.php index 95b1d8ec8..c9eab4ebe 100644 --- a/tests/tests/Gmagick/LayersTest.php +++ b/tests/tests/Gmagick/LayersTest.php @@ -84,6 +84,20 @@ public function testCount() $this->assertCount(42, $layers); } + public function testWebpFormatIsAllowedAsAnimatedFormat() + { + $palette = new RGB(); + $resource = $this->getMockBuilder('\Gmagick')->getMock(); + + $resource->expects($this->atLeastOnce()) + ->method('getNumberImages') + ->will($this->returnValue(42)); + + $layers = new Layers(new Image($resource, $palette, new MetadataBag()), $palette, $resource); + + $layers->animate('webp', 200, 0); + } + public function testGetLayer() { $this->checkGmagickMockable(); diff --git a/tests/tests/Imagick/LayersTest.php b/tests/tests/Imagick/LayersTest.php index 3454aadea..15d964d3f 100644 --- a/tests/tests/Imagick/LayersTest.php +++ b/tests/tests/Imagick/LayersTest.php @@ -83,6 +83,20 @@ public function testCount() $this->assertCount(42, $layers); } + public function testWebpFormatIsAllowedAsAnimatedFormat() + { + $palette = new RGB(); + $resource = $this->getMockBuilder('\Imagick')->getMock(); + + $resource->expects($this->atLeastOnce()) + ->method('getNumberImages') + ->will($this->returnValue(42)); + + $layers = new Layers(new Image($resource, $palette, new MetadataBag()), $palette, $resource); + + $layers->animate('webp', 200, 0); + } + public function testGetLayer() { $palette = new RGB();