1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-13 17:34:04 +02:00

Refactor BackupCommand to use native clone

This commit is contained in:
Daniel Hensby
2017-09-12 11:49:40 +01:00
parent d0c1415846
commit 047ae11ae0
3 changed files with 16 additions and 20 deletions

View File

@@ -15,17 +15,8 @@ class BackupCommand extends \Intervention\Image\Commands\AbstractCommand
$backupName = $this->argument(0)->value();
// clone current image resource
$size = $image->getSize();
$clone = imagecreatetruecolor($size->width, $size->height);
imagealphablending($clone, false);
imagesavealpha($clone, true);
$transparency = imagecolorallocatealpha($clone, 0, 0, 0, 127);
imagefill($clone, 0, 0, $transparency);
// copy image to clone
imagecopy($clone, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
$image->setBackup($clone, $backupName);
$clone = clone $image;
$image->setBackup($clone->getCore(), $backupName);
return true;
}

View File

@@ -15,7 +15,8 @@ class BackupCommand extends \Intervention\Image\Commands\AbstractCommand
$backupName = $this->argument(0)->value();
// clone current image resource
$image->setBackup(clone $image->getCore(), $backupName);
$clone = clone $image;
$image->setBackup($clone->getCore(), $backupName);
return true;
}

View File

@@ -12,11 +12,11 @@ class BackupCommandTest extends PHPUnit_Framework_TestCase
public function testGdWithoutName()
{
$size = Mockery::mock('Intervention\Image\Size', array(800, 600));
$driver = Mockery::mock('Intervention\Image\Gd\Driver');
$driver->shouldReceive('cloneCore')->once();
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$image = Mockery::mock('Intervention\Image\Image');
$image = Mockery::mock('Intervention\Image\Image', array($driver));
$image->shouldReceive('getCore')->once()->andReturn($resource);
$image->shouldReceive('getSize')->once()->andReturn($size);
$image->shouldReceive('setBackup')->once();
$command = new BackupGd(array());
$result = $command->execute($image);
@@ -25,11 +25,11 @@ class BackupCommandTest extends PHPUnit_Framework_TestCase
public function testGdWithName()
{
$size = Mockery::mock('Intervention\Image\Size', array(800, 600));
$driver = Mockery::mock('Intervention\Image\Gd\Driver');
$driver->shouldReceive('cloneCore')->once();
$resource = imagecreatefromjpeg(__DIR__.'/images/test.jpg');
$image = Mockery::mock('Intervention\Image\Image');
$image = Mockery::mock('Intervention\Image\Image', array($driver));
$image->shouldReceive('getCore')->once()->andReturn($resource);
$image->shouldReceive('getSize')->once()->andReturn($size);
$image->shouldReceive('setBackup')->once();
$command = new BackupGd(array('name' => 'fooBackup'));
$result = $command->execute($image);
@@ -38,8 +38,10 @@ class BackupCommandTest extends PHPUnit_Framework_TestCase
public function testImagickWithoutName()
{
$driver = Mockery::mock('Intervention\Image\Imagick\Driver');
$driver->shouldReceive('cloneCore')->once();
$imagick = Mockery::mock('Imagick');
$image = Mockery::mock('Intervention\Image\Image');
$image = Mockery::mock('Intervention\Image\Image', array($driver));
$image->shouldReceive('getCore')->once()->andReturn($imagick);
$image->shouldReceive('setBackup')->once();
$command = new BackupImagick(array());
@@ -49,8 +51,10 @@ class BackupCommandTest extends PHPUnit_Framework_TestCase
public function testImagickWithName()
{
$driver = Mockery::mock('Intervention\Image\Imagick\Driver');
$driver->shouldReceive('cloneCore')->once();
$imagick = Mockery::mock('Imagick');
$image = Mockery::mock('Intervention\Image\Image');
$image = Mockery::mock('Intervention\Image\Image', array($driver));
$image->shouldReceive('getCore')->once()->andReturn($imagick);
$image->shouldReceive('setBackup')->once();
$command = new BackupImagick(array('name' => 'fooBackup'));