-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoImageHelperController.php
76 lines (63 loc) · 2.59 KB
/
DemoImageHelperController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* Demo for the ImageHelper
*
* - Images aalphamosaïques
*/
namespace service\controllers;
class DemoImageHelperController extends \MiniPaviFwk\controllers\MultipageController
{
public function __construct(array $context, array $params = [])
{
parent::__construct($context['image_page'], 8, $context, $params);
}
public function multipageSavePageNumber(int $page_num): void
{
$this->context['image_page'] = $page_num;
}
public function ecran(): string
{
$videotex = new \MiniPaviFwk\helpers\VideotexHelper();
$videotex
->page("demo-controller")
->position(3, 31)
->ecritUnicode("Page " . $this->multipage_page_num . "/" . $this->multipage_nb_pages);
$videotex->ecritVideotex(
$this->displayDemoImage($this->multipage_page_num - 1, $this->multipage_page_num <= 4)
);
$videotex->position(24, 8)->inversionDebut()->ecritUnicode(" SUITE | RETOUR | SOMMAIRE ")->inversionFin();
return $videotex->getOutput();
}
public function getCmd(): array
{
return \MiniPaviFwk\cmd\ZoneSaisieCmd::createMiniPaviCmd(null, 24, 40, 1, false);
}
public function choixSommaire(): ?\MiniPaviFwk\actions\Action
{
return new \MiniPaviFwk\actions\PageAction($this->context, 'demo-sommaire');
}
private function displayDemoImage(int $image_num, bool $relative): string
{
$videotex = new \MiniPaviFwk\helpers\VideotexHelper();
// Create the images, first bath in relative position then centered, second in absolute position
$gdImage = imagecreatefromjpeg(\SERVICE_DIR . '/images/example' . ($image_num % 4) . '.jpg');
if ($relative) {
// 4 firsts created in relative position and centered
list($videotex_image, $lignes, $cols) =
\MiniPaviFwk\helpers\ImageHelper::imageToAlphamosaic($gdImage, 20, 40);
$videotex->position(3, 1)->ecritUnicode("$lignes lignes x $cols cols");
// Center the image for output!
$ligne = 4 + floor((20 - $lignes) / 2.0);
$col = 1 + floor((40 - $cols) / 2.0);
$videotex
->position($ligne, $col);
} else {
// 4 lasts in absolute position
list($videotex_image, $lignes, $cols) =
\MiniPaviFwk\helpers\ImageHelper::imageToAlphamosaic($gdImage, 16, 32, false, 4, 3);
$videotex->position(3, 1)->ecritUnicode("$lignes lignes x $cols cols");
}
$videotex->ecritVideotex($videotex_image);
return $videotex->getOutput();
}
}