ResetCommand.php 911 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Intervention\Image\Gd\Commands;
  3. use Intervention\Image\Commands\AbstractCommand;
  4. use Intervention\Image\Exception\RuntimeException;
  5. class ResetCommand extends AbstractCommand
  6. {
  7. /**
  8. * Resets given image to its backup state
  9. *
  10. * @param \Intervention\Image\Image $image
  11. * @return boolean
  12. */
  13. public function execute($image)
  14. {
  15. $backupName = $this->argument(0)->value();
  16. if (is_resource($backup = $image->getBackup($backupName))) {
  17. // destroy current resource
  18. imagedestroy($image->getCore());
  19. // clone backup
  20. $backup = $image->getDriver()->cloneCore($backup);
  21. // reset to new resource
  22. $image->setCore($backup);
  23. return true;
  24. }
  25. throw new RuntimeException(
  26. "Backup not available. Call backup() before reset()."
  27. );
  28. }
  29. }