1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 17:19:50 +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); imagesavealpha($clone, true);
imagecopy($clone, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height); imagecopy($clone, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
$image->setBackup($backupName, $clone); $image->setBackup($clone, $backupName);
return true; return true;
} }

View File

@@ -19,9 +19,9 @@ class Image extends File
protected $core; 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(); protected $backups = array();
@@ -162,9 +162,15 @@ class Image extends File
* @param string $name * @param string $name
* @return mixed * @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]; return $this->backups[$name];
} }
@@ -172,27 +178,30 @@ class Image extends File
/** /**
* Sets current image backup * Sets current image backup
* *
* @param mixed $resource
* @param string $name * @param string $name
* @param mixed $value
* @return self * @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 $name = is_null($name) ? 'default' : $name;
if (func_num_args() == 1) {
$value = func_get_arg(0);
$name = 'default';
}
elseif (is_null($name))
{
$name = 'default';
}
$this->backups[$name] = $value; $this->backups[$name] = $resource;
return $this; 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 * 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(); $backupName = $this->argument(0)->value();
// clone current image resource // clone current image resource
$image->setBackup($backupName, clone $image->getCore()); $image->setBackup(clone $image->getCore(), $backupName);
return true; return true;
} }