mirror of
https://github.com/Intervention/image.git
synced 2025-09-02 10:23:29 +02:00
Add methods add() to cores
This commit is contained in:
@@ -10,6 +10,13 @@ class Core extends Collection implements CoreInterface
|
|||||||
{
|
{
|
||||||
protected int $loops = 0;
|
protected int $loops = 0;
|
||||||
|
|
||||||
|
public function add(FrameInterface $frame): CoreInterface
|
||||||
|
{
|
||||||
|
$this->push($frame);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function native(): mixed
|
public function native(): mixed
|
||||||
{
|
{
|
||||||
return $this->first()->native();
|
return $this->first()->native();
|
||||||
|
@@ -17,6 +17,26 @@ class Core implements CoreInterface, Iterator
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function add(FrameInterface $frame): CoreInterface
|
||||||
|
{
|
||||||
|
$imagick = $frame->native();
|
||||||
|
|
||||||
|
$imagick->setImageDelay($frame->delay());
|
||||||
|
$imagick->setImageDispose($frame->dispose());
|
||||||
|
|
||||||
|
$size = $frame->size();
|
||||||
|
$imagick->setImagePage(
|
||||||
|
$size->width(),
|
||||||
|
$size->height(),
|
||||||
|
$frame->offsetLeft(),
|
||||||
|
$frame->offsetTop()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->imagick->addImage($imagick);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function count(): int
|
public function count(): int
|
||||||
{
|
{
|
||||||
return $this->imagick->getNumberImages();
|
return $this->imagick->getNumberImages();
|
||||||
|
@@ -36,6 +36,14 @@ interface CoreInterface extends Traversable
|
|||||||
*/
|
*/
|
||||||
public function frame(int $position): FrameInterface;
|
public function frame(int $position): FrameInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add new frame to core
|
||||||
|
*
|
||||||
|
* @param FrameInterface $frame
|
||||||
|
* @return CoreInterface
|
||||||
|
*/
|
||||||
|
public function add(FrameInterface $frame): CoreInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return number of repetitions of an animated image
|
* Return number of repetitions of an animated image
|
||||||
*
|
*
|
||||||
|
@@ -17,6 +17,17 @@ class CoreTest extends TestCase
|
|||||||
$this->assertInstanceOf(GdImage::class, $core->native());
|
$this->assertInstanceOf(GdImage::class, $core->native());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAdd(): void
|
||||||
|
{
|
||||||
|
$gd1 = imagecreatetruecolor(3, 2);
|
||||||
|
$gd2 = imagecreatetruecolor(3, 2);
|
||||||
|
$core = new Core([new Frame($gd1)]);
|
||||||
|
$this->assertEquals(1, $core->count());
|
||||||
|
$result = $core->add(new Frame($gd2));
|
||||||
|
$this->assertEquals(2, $core->count());
|
||||||
|
$this->assertInstanceOf(Core::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSetNative(): void
|
public function testSetNative(): void
|
||||||
{
|
{
|
||||||
$gd1 = imagecreatetruecolor(3, 2);
|
$gd1 = imagecreatetruecolor(3, 2);
|
||||||
|
@@ -17,6 +17,17 @@ class CoreTest extends TestCase
|
|||||||
$this->assertInstanceOf(Core::class, $core);
|
$this->assertInstanceOf(Core::class, $core);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAdd(): void
|
||||||
|
{
|
||||||
|
$imagick = new Imagick();
|
||||||
|
$imagick->newImage(100, 100, new ImagickPixel('red'));
|
||||||
|
$core = new Core($imagick);
|
||||||
|
$this->assertEquals(1, $core->count());
|
||||||
|
$result = $core->add(new Frame(clone $imagick));
|
||||||
|
$this->assertEquals(2, $core->count());
|
||||||
|
$this->assertInstanceOf(Core::class, $result);
|
||||||
|
}
|
||||||
|
|
||||||
public function testCount(): void
|
public function testCount(): void
|
||||||
{
|
{
|
||||||
$imagick = new Imagick();
|
$imagick = new Imagick();
|
||||||
|
Reference in New Issue
Block a user