diff --git a/src/Builder.php b/src/Builder.php index 3f10550..67ed49f 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -96,10 +96,16 @@ public function setLoops(int $loops): self * @param float $delay time delay in seconds * @param int $left position offset in pixels from left * @param int $top position offset in pixels from top + * @param bool $interlaced * @return Builder */ - public function addFrame(string $source, float $delay = 0, int $left = 0, int $top = 0): self - { + public function addFrame( + string $source, + float $delay = 0, + int $left = 0, + int $top = 0, + bool $interlaced = false + ): self { $frame = new FrameBlock(); $source = Decoder::decode($source); @@ -113,7 +119,7 @@ public function addFrame(string $source, float $delay = 0, int $left = 0, int $t // store image $frame->setTableBasedImage( - $this->buildTableBasedImage($source, $left, $top) + $this->buildTableBasedImage($source, $left, $top, $interlaced) ); // add frame @@ -156,10 +162,15 @@ protected function buildGraphicControlExtension( * @param GifDataStream $source * @param int $left * @param int $top + * @param bool $interlaced * @return TableBasedImage */ - protected function buildTableBasedImage(GifDataStream $source, int $left, int $top): TableBasedImage - { + protected function buildTableBasedImage( + GifDataStream $source, + int $left, + int $top, + bool $interlaced + ): TableBasedImage { $block = new TableBasedImage(); $block->setImageDescriptor(new ImageDescriptor()); @@ -183,6 +194,9 @@ protected function buildTableBasedImage(GifDataStream $source, int $left, int $t // set position $block->getImageDescriptor()->setPosition($left, $top); + // set interlaced flag + $block->getImageDescriptor()->setInterlaced($interlaced); + // add image data from source $block->setImageData($source->getFirstFrame()->getImageData()); diff --git a/tests/Unit/BuilderTest.php b/tests/Unit/BuilderTest.php index 972397b..906f711 100644 --- a/tests/Unit/BuilderTest.php +++ b/tests/Unit/BuilderTest.php @@ -49,5 +49,18 @@ public function testAddFrame(): void $this->assertEquals(25, $gif->getFirstFrame()->getGraphicControlExtension()->getDelay()); $this->assertEquals(1, $gif->getFirstFrame()->getImageDescriptor()->getLeft()); $this->assertEquals(2, $gif->getFirstFrame()->getImageDescriptor()->getTop()); + $this->assertFalse($gif->getFirstFrame()->getImageDescriptor()->isInterlaced()); + } + + public function testAddFrameInterlace(): void + { + $builder = Builder::canvas(320, 240); + $result = $builder->addFrame($this->getTestImagePath('red.gif'), 0.25, 1, 2, true); + $this->assertInstanceOf(Builder::class, $result); + $gif = $builder->getGifDataStream(); + $this->assertEquals(25, $gif->getFirstFrame()->getGraphicControlExtension()->getDelay()); + $this->assertEquals(1, $gif->getFirstFrame()->getImageDescriptor()->getLeft()); + $this->assertEquals(2, $gif->getFirstFrame()->getImageDescriptor()->getTop()); + $this->assertTrue($gif->getFirstFrame()->getImageDescriptor()->isInterlaced()); } }