1 | <?php |
||
15 | class CloudRenderer |
||
16 | { |
||
17 | /** |
||
18 | * @param Cloud $cloud |
||
19 | * @param bool $drawBoundingBoxes |
||
20 | * @return \Imagine\Gd\Image|\Imagine\Image\ImageInterface |
||
21 | */ |
||
22 | 1 | public function render(Cloud $cloud, FontsFactory $fontsFactory, $drawBoundingBoxes = false) |
|
23 | { |
||
24 | 1 | $imagine = new Imagine(); |
|
25 | 1 | $size = new Box($cloud->getWidth(), $cloud->getHeight()); |
|
26 | 1 | $image = $imagine->create( |
|
27 | $size, |
||
28 | 1 | new Color($cloud->getBackgroundColor()) |
|
29 | ); |
||
30 | |||
31 | /** @var \SixtyNine\Cloud\Model\CloudWord $word */ |
||
32 | 1 | foreach ($cloud->getWords() as $word) { |
|
33 | |||
34 | 1 | if (!$word->getIsVisible()) { |
|
35 | continue; |
||
36 | } |
||
37 | |||
38 | 1 | $font = $fontsFactory->getImagineFont($cloud->getFont(), $word->getSize(), $word->getColor()); |
|
39 | 1 | $angle = $word->getAngle(); |
|
40 | 1 | $pos = $word->getPosition(); |
|
41 | 1 | $box =$word->getBox(); |
|
42 | |||
43 | 1 | $image->draw()->text( |
|
44 | 1 | $word->getText(), |
|
45 | $font, |
||
46 | 1 | new Point($pos[0], $pos[1]), |
|
47 | $angle |
||
48 | ); |
||
49 | |||
50 | 1 | if ($drawBoundingBoxes) { |
|
51 | 1 | if ($word->getAngle() === 0) { |
|
52 | $points = array( |
||
53 | 1 | new Point($pos[0], $pos[1]), |
|
54 | 1 | new Point($pos[0] + $box[0], $pos[1]), |
|
55 | 1 | new Point($pos[0] + $box[0], $pos[1] + $box[1]), |
|
56 | 1 | new Point($pos[0], $pos[1] + $box[1]), |
|
57 | ); |
||
58 | } else { |
||
59 | $points = array( |
||
60 | new Point($pos[0], $pos[1] + $box[0]), |
||
61 | new Point($pos[0] - $box[0], $pos[1] + $box[0]), |
||
62 | new Point($pos[0] - $box[0], $pos[1] - $box[1] + $box[0]), |
||
63 | new Point($pos[0], $pos[1] - $box[1] + $box[0]), |
||
64 | ); |
||
65 | } |
||
66 | 1 | $image->draw()->polygon($points, new Color(0xFF0000)); |
|
67 | } |
||
68 | } |
||
69 | |||
70 | 1 | return $image; |
|
71 | } |
||
72 | |||
73 | 1 | public function renderUsher( |
|
99 | } |
||
100 |