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 | if ($angle === 0) { |
|
44 | 1 | $image->draw()->text( |
|
45 | 1 | $word->getText(), |
|
46 | $font, |
||
47 | 1 | new Point($pos[0], $pos[1]), |
|
48 | $angle |
||
49 | ); |
||
50 | } else { |
||
51 | 1 | $image->draw()->text( |
|
52 | 1 | $word->getText(), |
|
53 | $font, |
||
54 | 1 | new Point($pos[0], $pos[1] - $box[0]), |
|
55 | $angle |
||
56 | ); |
||
57 | } |
||
58 | |||
59 | 1 | if ($drawBoundingBoxes) { |
|
60 | 1 | if ($word->getAngle() === 0) { |
|
61 | $points = array( |
||
62 | 1 | new Point($pos[0], $pos[1]), |
|
63 | 1 | new Point($pos[0] + $box[0], $pos[1]), |
|
64 | 1 | new Point($pos[0] + $box[0], $pos[1] + $box[1]), |
|
65 | 1 | new Point($pos[0], $pos[1] + $box[1]), |
|
66 | ); |
||
67 | } else { |
||
68 | $points = array( |
||
69 | 1 | new Point($pos[0], $pos[1]), |
|
70 | 1 | new Point($pos[0] - $box[0], $pos[1]), |
|
71 | 1 | new Point($pos[0] - $box[0], $pos[1] - $box[1]), |
|
72 | 1 | new Point($pos[0], $pos[1] - $box[1]), |
|
73 | ); |
||
74 | } |
||
75 | 1 | $image->draw()->polygon($points, new Color(0xFF0000)); |
|
76 | } |
||
77 | } |
||
78 | |||
79 | 1 | return $image; |
|
80 | } |
||
81 | |||
82 | 1 | public function renderUsher( |
|
108 | } |
||
109 |