Conditions | 5 |
Paths | 3 |
Total Lines | 20 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
28 | public function execute(Image $image) |
||
29 | { |
||
30 | if ($image->getWidth() == $this->options->getDimention()->getWidth() and $image->getHeight() == $this->options->getDimention()->getHeight()) { |
||
|
|||
31 | return $image; |
||
32 | } |
||
33 | |||
34 | if ($this->options->getDimention()->getWidth() > $image->getWidth() || $this->options->getDimention()->getHeight() > $image->getHeight()) { |
||
35 | throw new InvalidArgumentException(sprintf('Crop area exceed, max dimensions are: %s X %s', $image->getWidth(), $image->getHeight())); |
||
36 | } |
||
37 | |||
38 | /** @var CropCommandOption $options */ |
||
39 | $options = $this->options; |
||
40 | $newImage = imagecrop($image->getResource(), [ |
||
41 | 'x' => $options->getCoordinate1()->getX(), |
||
42 | 'y' => $options->getCoordinate1()->getY(), |
||
43 | 'width' => $options->getDimention()->getWidth(), |
||
44 | 'height' => $options->getDimention()->getHeight(), |
||
45 | ]); |
||
46 | |||
47 | return $image->assignResource($newImage); |
||
48 | } |
||
50 |