mirror of
https://github.com/Intervention/image.git
synced 2025-08-21 13:11:18 +02:00
added possibility to reset multiple times to a backup
This commit is contained in:
@@ -16,8 +16,12 @@ class ResetCommand extends \Intervention\Image\Commands\AbstractCommand
|
|||||||
|
|
||||||
if (is_resource($backup = $image->getBackup($backupName))) {
|
if (is_resource($backup = $image->getBackup($backupName))) {
|
||||||
|
|
||||||
// destroy old resource
|
// destroy current resource
|
||||||
imagedestroy($image->getCore());
|
imagedestroy($image->getCore());
|
||||||
|
|
||||||
|
// clone backup
|
||||||
|
$backup = $image->getDriver()->cloneCore($backup);
|
||||||
|
|
||||||
// reset to new resource
|
// reset to new resource
|
||||||
$image->setCore($backup);
|
$image->setCore($backup);
|
||||||
|
|
||||||
|
@@ -18,9 +18,12 @@ class ResetCommand extends \Intervention\Image\Commands\AbstractCommand
|
|||||||
|
|
||||||
if ($backup instanceof \Imagick) {
|
if ($backup instanceof \Imagick) {
|
||||||
|
|
||||||
// destroy old core
|
// destroy current core
|
||||||
$image->getCore()->clear();
|
$image->getCore()->clear();
|
||||||
|
|
||||||
|
// clone backup
|
||||||
|
$backup = clone $backup;
|
||||||
|
|
||||||
// reset to new resource
|
// reset to new resource
|
||||||
$image->setCore($backup);
|
$image->setCore($backup);
|
||||||
|
|
||||||
|
@@ -1106,6 +1106,29 @@ class GdSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertTransparentPosition($img, 0, 0);
|
$this->assertTransparentPosition($img, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testResetToNamed()
|
||||||
|
{
|
||||||
|
$img = $this->manager()->make('tests/images/tile.png');
|
||||||
|
$img->backup('original');
|
||||||
|
$img->resize(30, 20);
|
||||||
|
$img->backup('30x20');
|
||||||
|
|
||||||
|
// reset to original
|
||||||
|
$img->reset('original');
|
||||||
|
$this->assertEquals(16, $img->getWidth());
|
||||||
|
$this->assertEquals(16, $img->getHeight());
|
||||||
|
|
||||||
|
// reset to 30x20
|
||||||
|
// $img->reset('30x20');
|
||||||
|
// $this->assertEquals(30, $img->getWidth());
|
||||||
|
// $this->assertEquals(20, $img->getHeight());
|
||||||
|
|
||||||
|
// reset to original again
|
||||||
|
$img->reset('original');
|
||||||
|
$this->assertEquals(16, $img->getWidth());
|
||||||
|
$this->assertEquals(16, $img->getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
public function testLimitColors()
|
public function testLimitColors()
|
||||||
{
|
{
|
||||||
$img = $this->manager()->make('tests/images/trim.png');
|
$img = $this->manager()->make('tests/images/trim.png');
|
||||||
|
@@ -1081,6 +1081,29 @@ class ImagickSystemTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertTransparentPosition($img, 0, 0);
|
$this->assertTransparentPosition($img, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testResetToNamed()
|
||||||
|
{
|
||||||
|
$img = $this->manager()->make('tests/images/tile.png');
|
||||||
|
$img->backup('original');
|
||||||
|
$img->resize(30, 20);
|
||||||
|
$img->backup('30x20');
|
||||||
|
|
||||||
|
// reset to original
|
||||||
|
$img->reset('original');
|
||||||
|
$this->assertEquals(16, $img->getWidth());
|
||||||
|
$this->assertEquals(16, $img->getHeight());
|
||||||
|
|
||||||
|
// reset to 30x20
|
||||||
|
$img->reset('30x20');
|
||||||
|
$this->assertEquals(30, $img->getWidth());
|
||||||
|
$this->assertEquals(20, $img->getHeight());
|
||||||
|
|
||||||
|
// reset to original again
|
||||||
|
$img->reset('original');
|
||||||
|
$this->assertEquals(16, $img->getWidth());
|
||||||
|
$this->assertEquals(16, $img->getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
public function testLimitColors()
|
public function testLimitColors()
|
||||||
{
|
{
|
||||||
$img = $this->manager()->make('tests/images/trim.png');
|
$img = $this->manager()->make('tests/images/trim.png');
|
||||||
|
@@ -15,7 +15,10 @@ class ResetCommandTest extends PHPUnit_Framework_TestCase
|
|||||||
$size = Mockery::mock('Intervention\Image\Size', array(800, 600));
|
$size = Mockery::mock('Intervention\Image\Size', array(800, 600));
|
||||||
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
|
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
|
||||||
$image = Mockery::mock('Intervention\Image\Image');
|
$image = Mockery::mock('Intervention\Image\Image');
|
||||||
|
$driver = Mockery::mock('Intervention\Image\Gd\Driver');
|
||||||
|
$driver->shouldReceive('cloneCore')->with($resource)->once()->andReturn($resource);
|
||||||
$image->shouldReceive('getCore')->once()->andReturn($resource);
|
$image->shouldReceive('getCore')->once()->andReturn($resource);
|
||||||
|
$image->shouldReceive('getDriver')->once()->andReturn($driver);
|
||||||
$image->shouldReceive('setCore')->once();
|
$image->shouldReceive('setCore')->once();
|
||||||
$image->shouldReceive('getBackup')->once()->andReturn($resource);
|
$image->shouldReceive('getBackup')->once()->andReturn($resource);
|
||||||
$command = new ResetGd(array());
|
$command = new ResetGd(array());
|
||||||
@@ -28,6 +31,9 @@ class ResetCommandTest extends PHPUnit_Framework_TestCase
|
|||||||
$size = Mockery::mock('Intervention\Image\Size', array(800, 600));
|
$size = Mockery::mock('Intervention\Image\Size', array(800, 600));
|
||||||
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
|
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
|
||||||
$image = Mockery::mock('Intervention\Image\Image');
|
$image = Mockery::mock('Intervention\Image\Image');
|
||||||
|
$driver = Mockery::mock('Intervention\Image\Gd\Driver');
|
||||||
|
$driver->shouldReceive('cloneCore')->with($resource)->once()->andReturn($resource);
|
||||||
|
$image->shouldReceive('getDriver')->once()->andReturn($driver);
|
||||||
$image->shouldReceive('getCore')->once()->andReturn($resource);
|
$image->shouldReceive('getCore')->once()->andReturn($resource);
|
||||||
$image->shouldReceive('setCore')->once();
|
$image->shouldReceive('setCore')->once();
|
||||||
$image->shouldReceive('getBackup')->once()->withArgs(array('fooBackup'))->andReturn($resource);
|
$image->shouldReceive('getBackup')->once()->withArgs(array('fooBackup'))->andReturn($resource);
|
||||||
|
Reference in New Issue
Block a user