Skip to content

Commit

Permalink
Add tests for encoding animated & interlaced gif format
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Mar 26, 2024
1 parent 6b44c43 commit cdf5a87
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/ImagickTestCase.php
Expand Up @@ -35,4 +35,22 @@ public function createTestImage(int $width, int $height): Image
new Core($imagick)
);
}

public function createTestAnimation(): Image
{
$imagick = new Imagick();
$imagick->setFormat('gif');

for ($i = 0; $i < 3; $i++) {
$frame = new Imagick();
$frame->newImage(3, 2, new ImagickPixel('rgb(255, 0, 0)'), 'gif');
$frame->setImageDelay(10);
$imagick->addImage($frame);
}

return new Image(
new Driver(),
new Core($imagick)
);
}
}
11 changes: 11 additions & 0 deletions tests/Unit/Drivers/Gd/Encoders/GifEncoderTest.php
Expand Up @@ -36,4 +36,15 @@ public function testEncodeInterlaced(): void
Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced()
);
}

public function testEncodeInterlacedAnimation(): void
{
$image = $this->createTestAnimation(3, 2);
$encoder = new GifEncoder(interlaced: true);
$result = $encoder->encode($image);
$this->assertMediaType('image/gif', (string) $result);
$this->assertTrue(
Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced()
);
}
}
11 changes: 11 additions & 0 deletions tests/Unit/Drivers/Imagick/Encoders/GifEncoderTest.php
Expand Up @@ -36,4 +36,15 @@ public function testEncodeInterlaced(): void
Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced()
);
}

public function testEncodeInterlacedAnimation(): void
{
$image = $this->createTestAnimation();
$encoder = new GifEncoder(interlaced: true);
$result = $encoder->encode($image);
$this->assertMediaType('image/gif', (string) $result);
$this->assertTrue(
Decoder::decode((string) $result)->getFirstFrame()->getImageDescriptor()->isInterlaced()
);
}
}

0 comments on commit cdf5a87

Please sign in to comment.