Completed
Push — master ( 250788...86e483 )
by Dan
03:48
created

DebugUsherCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 14
nc 1
nop 2
1
<?php
2
3
namespace SixtyNine\Cloud\Command;
4
5
use Imagine\Gd\Image;
6
use Imagine\Gd\Imagine;
7
use Imagine\Image\Box;
8
use Imagine\Image\Color;
9
use SixtyNine\Cloud\Factory\FontsFactory;
10
use SixtyNine\Cloud\Factory\PlacerFactory;
11
use SixtyNine\Cloud\Model\Cloud;
12
use SixtyNine\Cloud\Renderer\CloudRenderer;
13
use Symfony\Component\Console\Command\Command;
14
use Symfony\Component\Console\Input\InputArgument;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class DebugUsherCommand extends Command
20
{
21
    /** {@inheritdoc} */
22
    protected function configure()
23
    {
24
        $this
25
            ->setName('debug:usher')
26
            ->setDescription('Show the path a word placer uses')
27
            ->addArgument('placer', InputArgument::REQUIRED, 'The name of the words placer')
28
            ->addOption('width', null, InputOption::VALUE_OPTIONAL, 'Width of the image', 800)
29
            ->addOption('height', null, InputOption::VALUE_OPTIONAL, 'Height of the image', 600)
30
            ->addOption('color', null, InputOption::VALUE_OPTIONAL, 'Color of the path', '#FF0000')
31
            ->addOption('background-color', null, InputOption::VALUE_OPTIONAL, 'Background color of the cloud', '#FFFFFF')
32
            ->addOption('save-to-file', null, InputOption::VALUE_OPTIONAL, 'If set to a file name, the output will be saved there')
33
            ->addOption('format', null, InputOption::VALUE_OPTIONAL, 'Output format (gif, jpeg, png)', 'png')
34
        ;
35
    }
36
37
    /** {@inheritdoc} */
38
    protected function execute(InputInterface $input, OutputInterface $output)
39
    {
40
        $cloud = (new Cloud())
41
            ->setWidth($input->getOption('width'))
42
            ->setHeight($input->getOption('height'))
43
            ->setBackgroundColor($input->getOption('background-color'))
44
        ;
45
        $helper = new CommandsHelper();
46
        $renderer = new CloudRenderer($cloud, FontsFactory::create(BASE_PATH . '/fonts'));
47
        $placerName = $helper->getPlacer($input->getArgument('placer'));
48
49
        $placer = PlacerFactory::getInstance()->getPlacer(
50
            $placerName,
51
            $input->getOption('width'),
52
            $input->getOption('height')
53
        );
54
55
        $renderer->renderUsher($placer, $input->getOption('color'));
56
57
        $helper->output($renderer->getImage(), $input->getOption('format'), $input->getOption('save-to-file'));
58
    }
59
}
60