1 | <?php |
||
16 | class CloudRenderer |
||
17 | { |
||
18 | /** |
||
19 | * @param Cloud $cloud |
||
20 | * @param \SixtyNine\Cloud\Factory\FontsFactory $fontsFactory |
||
21 | * @param bool $drawBoundingBoxes |
||
22 | * @return \Imagine\Gd\Image|\Imagine\Image\ImageInterface |
||
23 | */ |
||
24 | 1 | public function render(Cloud $cloud, FontsFactory $fontsFactory, $drawBoundingBoxes = false) |
|
25 | { |
||
26 | 1 | $drawer = Drawer::create($fontsFactory) |
|
27 | 1 | ->createImage($cloud->getWidth(), $cloud->getHeight(), $cloud->getBackgroundColor()) |
|
28 | 1 | ->setFont($cloud->getFont()) |
|
29 | ; |
||
30 | |||
31 | /** @var \SixtyNine\Cloud\Model\CloudWord $word */ |
||
32 | 1 | foreach ($cloud->getWords() as $word) { |
|
33 | |||
34 | 1 | if (!$word->getIsVisible()) { |
|
35 | 1 | continue; |
|
36 | } |
||
37 | |||
38 | 1 | $pos = $word->getPosition(); |
|
39 | 1 | $box = $word->getBox(); |
|
40 | |||
41 | 1 | if ($word->getAngle() === 270) { |
|
42 | 1 | $drawer->drawText($pos[0] + $box->getWidth(), $pos[1] + $box->getHeight() - $word->getSize(), $word->getText(), $word->getSize(), $word->getColor(), $word->getAngle()); |
|
43 | } else { |
||
44 | 1 | $drawer->drawText($pos[0], $pos[1], $word->getText(), $word->getSize(), $word->getColor(), $word->getAngle()); |
|
45 | } |
||
46 | |||
47 | 1 | if ($drawBoundingBoxes) { |
|
48 | 1 | $drawer->drawBox($box->getX(), $box->getY(), $box->getWidth(), $box->getHeight(), '#ff0000'); |
|
49 | } |
||
50 | } |
||
51 | |||
52 | 1 | return $drawer->getImage(); |
|
53 | } |
||
54 | |||
55 | 2 | public function renderUsher( |
|
81 | } |
||
82 |