1 | <?php |
||
2 | |||
3 | namespace Jackal\ImageMerge\Command\Asset; |
||
4 | |||
5 | use Jackal\ImageMerge\Command\AbstractCommand; |
||
6 | use Jackal\ImageMerge\Command\Options\TextCommandOption; |
||
7 | use Jackal\ImageMerge\Exception\ModuleNotFoundException; |
||
8 | use Jackal\ImageMerge\Model\Image; |
||
9 | use Jackal\ImageMerge\Utils\ColorUtils; |
||
10 | |||
11 | /** |
||
12 | * Class TextAssetCommand |
||
13 | * @package Jackal\ImageMerge\Command\Asset |
||
14 | */ |
||
15 | class TextAssetCommand extends AbstractCommand |
||
16 | { |
||
17 | /** |
||
18 | * @param Image $image |
||
19 | * @return mixed |
||
20 | * @throws ModuleNotFoundException |
||
21 | */ |
||
22 | public function execute(Image $image) |
||
23 | { |
||
24 | /** @var TextCommandOption $options */ |
||
25 | $options = $this->options; |
||
26 | |||
27 | $color = ColorUtils::colorIdentifier($image->getResource(), |
||
28 | $options->getColor() |
||
29 | ); |
||
30 | |||
31 | $fontPixel = round($options->getText()->getFontSize() * 0.75); |
||
32 | |||
33 | if (!function_exists('imagettftext')) { |
||
34 | throw new ModuleNotFoundException('function imagettftext not installed'); |
||
35 | } |
||
36 | |||
37 | imagettftext($image->getResource(), $fontPixel, 0, |
||
38 | $options->getCoordinate1()->getX(), |
||
39 | $options->getCoordinate1()->getY() + $fontPixel, |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
40 | $color, $options->getText()->getFont(), $options->getText()->getText()); |
||
41 | |||
42 | return $image; |
||
43 | } |
||
44 | } |
||
45 |