1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 01:00:06 +02:00

Normalized delay

This commit is contained in:
Oliver Vogel
2021-10-21 16:27:27 +02:00
parent 0cf62e5f1d
commit 2927abf1a2
5 changed files with 17 additions and 16 deletions

View File

@@ -11,9 +11,9 @@ use Intervention\Image\Interfaces\ImageInterface;
class Frame extends AbstractFrame implements FrameInterface 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; protected $delay = 0;
@@ -48,12 +48,12 @@ class Frame extends AbstractFrame implements FrameInterface
return $this->core; return $this->core;
} }
public function getDelay(): int public function getDelay(): float
{ {
return $this->delay; return $this->delay;
} }
public function setDelay(int $delay): FrameInterface public function setDelay(float $delay): FrameInterface
{ {
$this->delay = $delay; $this->delay = $delay;

View File

@@ -20,14 +20,14 @@ class Frame extends AbstractFrame implements FrameInterface
return $this->core; 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; return $this;
} }

View File

@@ -6,8 +6,8 @@ interface FrameInterface
{ {
public function toImage(): ImageInterface; public function toImage(): ImageInterface;
public function getCore(); public function getCore();
public function getDelay(): int; public function getDelay(): float;
public function setDelay(int $delay): FrameInterface; public function setDelay(float $delay): FrameInterface;
public function getDispose(): int; public function getDispose(): int;
public function setDispose(int $dispose): FrameInterface; public function setDispose(int $dispose): FrameInterface;
public function setOffset(int $left, int $top): FrameInterface; public function setOffset(int $left, int $top): FrameInterface;

View File

@@ -24,9 +24,9 @@ class FrameTest extends TestCase
$frame = $this->getTestFrame(); $frame = $this->getTestFrame();
$this->assertEquals(0, $frame->getDelay()); $this->assertEquals(0, $frame->getDelay());
$result = $frame->setDelay(100); $result = $frame->setDelay(1.5);
$this->assertInstanceOf(Frame::class, $result); $this->assertInstanceOf(Frame::class, $result);
$this->assertEquals(100, $frame->getDelay()); $this->assertEquals(1.5, $frame->getDelay());
} }
public function testSetGetDispose() public function testSetGetDispose()

View File

@@ -14,7 +14,7 @@ class FrameTest extends TestCase
{ {
$imagick = new Imagick(); $imagick = new Imagick();
$imagick->newImage(3, 2, new ImagickPixel('red'), 'png'); $imagick->newImage(3, 2, new ImagickPixel('red'), 'png');
$imagick->setImageDelay(4); $imagick->setImageDelay(125); // 1.25 seconds
$imagick->setImageDispose(5); $imagick->setImageDispose(5);
$imagick->setImagePage(3, 2, 8, 9); $imagick->setImagePage(3, 2, 8, 9);
@@ -30,11 +30,12 @@ class FrameTest extends TestCase
public function testSetGetDelay() public function testSetGetDelay()
{ {
$frame = $this->getTestFrame(); $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->assertInstanceOf(Frame::class, $result);
$this->assertEquals(100, $frame->getDelay()); $this->assertEquals(2.5, $frame->getDelay());
$this->assertEquals(250, $frame->getCore()->getImageDelay());
} }
public function testSetGetDispose() public function testSetGetDispose()