1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 01:00:06 +02:00

named backup changes

This commit is contained in:
Oliver Vogel
2014-09-18 17:20:05 +02:00
parent 3acf5b71e0
commit ad72919fbc
3 changed files with 27 additions and 18 deletions

View File

@@ -21,7 +21,7 @@ class BackupCommand extends \Intervention\Image\Commands\AbstractCommand
imagesavealpha($clone, true);
imagecopy($clone, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
$image->setBackup($backupName, $clone);
$image->setBackup($clone, $backupName);
return true;
}

View File

@@ -19,9 +19,9 @@ class Image extends File
protected $core;
/**
* Image resource backup of current image processor
* Array of Image resource backups of current image processor
*
* @var mixed
* @var array
*/
protected $backups = array();
@@ -162,9 +162,15 @@ class Image extends File
* @param string $name
* @return mixed
*/
public function getBackup($name = 'default')
public function getBackup($name = null)
{
$name = (is_null($name) ? 'default' : $name);
$name = is_null($name) ? 'default' : $name;
if ( ! $this->backupExists($name)) {
throw new \Intervention\Image\Exception\RuntimeException(
"Backup with name ({$name}) not available. Call backup() before reset()."
);
}
return $this->backups[$name];
}
@@ -172,27 +178,30 @@ class Image extends File
/**
* Sets current image backup
*
* @param mixed $resource
* @param string $name
* @param mixed $value
* @return self
*/
public function setBackup($name, $value = null)
public function setBackup($resource, $name = null)
{
// If there is just 1 argument specified then it's the value
if (func_num_args() == 1) {
$value = func_get_arg(0);
$name = 'default';
}
elseif (is_null($name))
{
$name = 'default';
}
$name = is_null($name) ? 'default' : $name;
$this->backups[$name] = $value;
$this->backups[$name] = $resource;
return $this;
}
/**
* Checks if named backup exists
*
* @param string $name
* @return bool
*/
private function backupExists($name)
{
return array_key_exists($name, $this->backups);
}
/**
* Checks if current image is already encoded
*

View File

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