lucajackal85 /
ImageMerge
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Jackal\ImageMerge\Command\Asset; |
||
| 4 | |||
| 5 | use Exception; |
||
| 6 | use Jackal\ImageMerge\Command\AbstractCommand; |
||
| 7 | use Jackal\ImageMerge\Command\Options\SingleCoordinateFileObjectCommandOption; |
||
| 8 | use Jackal\ImageMerge\Model\Format\ImageReader; |
||
| 9 | use Jackal\ImageMerge\Model\Image; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Class ImageAsset |
||
| 13 | * @package Jackal\ImageMerge\Model\Asset |
||
| 14 | */ |
||
| 15 | class ImageAssetCommand extends AbstractCommand |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * ImageAssetCommand constructor. |
||
| 19 | * @param SingleCoordinateFileObjectCommandOption $options |
||
| 20 | */ |
||
| 21 | public function __construct(SingleCoordinateFileObjectCommandOption $options) |
||
| 22 | { |
||
| 23 | parent::__construct($options); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @return resource |
||
| 28 | * @throws Exception |
||
| 29 | */ |
||
| 30 | protected function getResourceToApply() |
||
| 31 | { |
||
| 32 | $res = ImageReader::fromPathname($this->options->getFile()); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 33 | |||
| 34 | return $res->getResource(); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return int |
||
| 39 | * @throws Exception |
||
| 40 | */ |
||
| 41 | protected function getWidth() |
||
| 42 | { |
||
| 43 | return imagesx($this->getResourceToApply()); |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return int |
||
| 48 | * @throws Exception |
||
| 49 | */ |
||
| 50 | protected function getHeight() |
||
| 51 | { |
||
| 52 | return imagesy($this->getResourceToApply()); |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param Image $image |
||
| 57 | * @return Image |
||
| 58 | * @throws Exception |
||
| 59 | */ |
||
| 60 | public function execute(Image $image) |
||
| 61 | { |
||
| 62 | /** @var SingleCoordinateFileObjectCommandOption $options */ |
||
| 63 | $options = $this->options; |
||
| 64 | imagecolortransparent($image->getResource()); |
||
| 65 | imagecopyresampled($image->getResource(), $this->getResourceToApply(), $options->getCoordinate1()->getX(), $options->getCoordinate1()->getY(), 0, 0, $this->getWidth(), $this->getHeight(), $this->getWidth(), $this->getHeight()); |
||
| 66 | $image->assignResource($image->getResource()); |
||
| 67 | |||
| 68 | return $image; |
||
| 69 | } |
||
| 70 | } |
||
| 71 |