FlipCommand.php 930 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Intervention\Image\Gd\Commands;
  3. class FlipCommand extends ResizeCommand
  4. {
  5. /**
  6. * Mirrors an image
  7. *
  8. * @param \Intervention\Image\Image $image
  9. * @return boolean
  10. */
  11. public function execute($image)
  12. {
  13. $mode = $this->argument(0)->value('h');
  14. $size = $image->getSize();
  15. $dst = clone $size;
  16. switch (strtolower($mode)) {
  17. case 2:
  18. case 'v':
  19. case 'vert':
  20. case 'vertical':
  21. $size->pivot->y = $size->height - 1;
  22. $size->height = $size->height * (-1);
  23. break;
  24. default:
  25. $size->pivot->x = $size->width - 1;
  26. $size->width = $size->width * (-1);
  27. break;
  28. }
  29. return $this->modify($image, 0, 0, $size->pivot->x, $size->pivot->y, $dst->width, $dst->height, $size->width, $size->height);
  30. }
  31. }