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:
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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'));
|
||||
|
Reference in New Issue
Block a user