mirror of
https://github.com/Intervention/image.git
synced 2025-08-29 16:50:07 +02:00
Normalized delay
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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()
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user