File indexing completed on 2025-01-26 05:29:14

0001 <?php
0002 
0003 namespace Intervention\Image\Imagick\Commands;
0004 
0005 class ResetCommand extends \Intervention\Image\Commands\AbstractCommand
0006 {
0007     /**
0008      * Resets given image to its backup state
0009      *
0010      * @param  \Intervention\Image\Image $image
0011      * @return boolean
0012      */
0013     public function execute($image)
0014     {
0015         $backupName = $this->argument(0)->value();
0016 
0017         $backup = $image->getBackup($backupName);
0018 
0019         if ($backup instanceof \Imagick) {
0020 
0021             // destroy current core
0022             $image->getCore()->clear();
0023 
0024             // clone backup
0025             $backup = clone $backup;
0026 
0027             // reset to new resource
0028             $image->setCore($backup);
0029 
0030             return true;
0031         }
0032 
0033         throw new \Intervention\Image\Exception\RuntimeException(
0034             "Backup not available. Call backup({$backupName}) before reset()."
0035         );
0036     }
0037 }