BackupCommand.php 908 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace Intervention\Image\Gd\Commands;
  3. class BackupCommand extends \Intervention\Image\Commands\AbstractCommand
  4. {
  5. /**
  6. * Saves a backups of current state of image core
  7. *
  8. * @param \Intervention\Image\Image $image
  9. * @return boolean
  10. */
  11. public function execute($image)
  12. {
  13. $backupName = $this->argument(0)->value();
  14. // clone current image resource
  15. $size = $image->getSize();
  16. $clone = imagecreatetruecolor($size->width, $size->height);
  17. imagealphablending($clone, false);
  18. imagesavealpha($clone, true);
  19. $transparency = imagecolorallocatealpha($clone, 0, 0, 0, 127);
  20. imagefill($clone, 0, 0, $transparency);
  21. // copy image to clone
  22. imagecopy($clone, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
  23. $image->setBackup($clone, $backupName);
  24. return true;
  25. }
  26. }