View file vendor/intervention/image/src/Intervention/Image/Gd/Commands/InsertCommand.php

File size: 1.11Kb
  1. <?php
  2.  
  3. namespace Intervention\Image\Gd\Commands;
  4.  
  5. use Intervention\Image\Commands\AbstractCommand;
  6.  
  7. class InsertCommand extends AbstractCommand
  8. {
  9. /**
  10. * Insert another image into given image
  11. *
  12. * @param \Intervention\Image\Image $image
  13. * @return boolean
  14. */
  15. public function execute($image)
  16. {
  17. $source = $this->argument(0)->required()->value();
  18. $position = $this->argument(1)->type('string')->value();
  19. $x = $this->argument(2)->type('digit')->value(0);
  20. $y = $this->argument(3)->type('digit')->value(0);
  21.  
  22. // build watermark
  23. $watermark = $image->getDriver()->init($source);
  24.  
  25. // define insertion point
  26. $image_size = $image->getSize()->align($position, $x, $y);
  27. $watermark_size = $watermark->getSize()->align($position);
  28. $target = $image_size->relativePosition($watermark_size);
  29.  
  30. // insert image at position
  31. imagealphablending($image->getCore(), true);
  32. return imagecopy($image->getCore(), $watermark->getCore(), $target->x, $target->y, 0, 0, $watermark_size->width, $watermark_size->height);
  33. }
  34. }