From 2927abf1a2091bb3b78022b16b38efaa9b988fe7 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 21 Oct 2021 16:27:27 +0200 Subject: [PATCH] Normalized delay --- src/Drivers/Gd/Frame.php | 8 ++++---- src/Drivers/Imagick/Frame.php | 8 ++++---- src/Interfaces/FrameInterface.php | 4 ++-- tests/Drivers/Gd/FrameTest.php | 4 ++-- tests/Drivers/Imagick/FrameTest.php | 9 +++++---- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Drivers/Gd/Frame.php b/src/Drivers/Gd/Frame.php index e5c9e0d1..2c7d18e1 100644 --- a/src/Drivers/Gd/Frame.php +++ b/src/Drivers/Gd/Frame.php @@ -11,9 +11,9 @@ use Intervention\Image\Interfaces\ImageInterface; class Frame extends AbstractFrame implements FrameInterface { /** - * Delay time in miliseconds after next frame is shown + * Delay time in seconds after next frame is shown * - * @var integer + * @var float */ protected $delay = 0; @@ -48,12 +48,12 @@ class Frame extends AbstractFrame implements FrameInterface return $this->core; } - public function getDelay(): int + public function getDelay(): float { return $this->delay; } - public function setDelay(int $delay): FrameInterface + public function setDelay(float $delay): FrameInterface { $this->delay = $delay; diff --git a/src/Drivers/Imagick/Frame.php b/src/Drivers/Imagick/Frame.php index c5c5652a..44873299 100644 --- a/src/Drivers/Imagick/Frame.php +++ b/src/Drivers/Imagick/Frame.php @@ -20,14 +20,14 @@ class Frame extends AbstractFrame implements FrameInterface return $this->core; } - public function getDelay(): int + public function getDelay(): float { - return $this->core->getImageDelay(); + return $this->core->getImageDelay() / 100; } - public function setDelay(int $delay): FrameInterface + public function setDelay(float $delay): FrameInterface { - $this->core->setImageDelay($delay); + $this->core->setImageDelay(round($delay * 100)); return $this; } diff --git a/src/Interfaces/FrameInterface.php b/src/Interfaces/FrameInterface.php index 2af3408c..4febaea9 100644 --- a/src/Interfaces/FrameInterface.php +++ b/src/Interfaces/FrameInterface.php @@ -6,8 +6,8 @@ interface FrameInterface { public function toImage(): ImageInterface; public function getCore(); - public function getDelay(): int; - public function setDelay(int $delay): FrameInterface; + public function getDelay(): float; + public function setDelay(float $delay): FrameInterface; public function getDispose(): int; public function setDispose(int $dispose): FrameInterface; public function setOffset(int $left, int $top): FrameInterface; diff --git a/tests/Drivers/Gd/FrameTest.php b/tests/Drivers/Gd/FrameTest.php index b17feb51..bb72f17b 100644 --- a/tests/Drivers/Gd/FrameTest.php +++ b/tests/Drivers/Gd/FrameTest.php @@ -24,9 +24,9 @@ class FrameTest extends TestCase $frame = $this->getTestFrame(); $this->assertEquals(0, $frame->getDelay()); - $result = $frame->setDelay(100); + $result = $frame->setDelay(1.5); $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(100, $frame->getDelay()); + $this->assertEquals(1.5, $frame->getDelay()); } public function testSetGetDispose() diff --git a/tests/Drivers/Imagick/FrameTest.php b/tests/Drivers/Imagick/FrameTest.php index c7c2a26d..30ae1467 100644 --- a/tests/Drivers/Imagick/FrameTest.php +++ b/tests/Drivers/Imagick/FrameTest.php @@ -14,7 +14,7 @@ class FrameTest extends TestCase { $imagick = new Imagick(); $imagick->newImage(3, 2, new ImagickPixel('red'), 'png'); - $imagick->setImageDelay(4); + $imagick->setImageDelay(125); // 1.25 seconds $imagick->setImageDispose(5); $imagick->setImagePage(3, 2, 8, 9); @@ -30,11 +30,12 @@ class FrameTest extends TestCase public function testSetGetDelay() { $frame = $this->getTestFrame(); - $this->assertEquals(4, $frame->getDelay()); + $this->assertEquals(1.25, $frame->getDelay()); - $result = $frame->setDelay(100); + $result = $frame->setDelay(2.5); $this->assertInstanceOf(Frame::class, $result); - $this->assertEquals(100, $frame->getDelay()); + $this->assertEquals(2.5, $frame->getDelay()); + $this->assertEquals(250, $frame->getCore()->getImageDelay()); } public function testSetGetDispose()