Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
barcode.php
1<?php
10
15{
16 private $generator;
17
21 private $type = BarcodeDictionary::TYPE_QR;
25 private $format = BarcodeDictionary::FORMAT_PNG;
26
30 private $options = [];
31
32 public function __construct()
33 {
34 $this->generator = new BarcodeGenerator();
35 }
36
41 public function render(string $data)
42 {
44 {
45 return $this->generator->render_svg($this->type, $data, $this->options);
46 }
47
48 $image = $this->generator->render_image($this->type, $data, $this->options);
49
50 ob_start();
51 switch ($this->format)
52 {
54 imagepng($image);
55 break;
57 imagegif($image);
58 break;
60 imagejpeg($image);
61 break;
62 }
63 imagedestroy($image);
64
65 return ob_get_clean();
66 }
67
71 public function print(string $data): void
72 {
73 $this->generator->output_image($this->format, $this->type, $data, $this->options);
74 }
75
80 public function type(string $type): self
81 {
82 $this->type = $type;
83 return $this;
84 }
85
90 public function format(string $format): self
91 {
92 $this->format = $format;
93 return $this;
94 }
95
100 public function options(array $options): self
101 {
102 $this->options = $options;
103 return $this;
104 }
105
111 public function option(string $option, $value): self
112 {
113 $this->options[$option] = $value;
114 return $this;
115 }
116}
render(string $data)
Definition barcode.php:41
print(string $data)
Definition barcode.php:71
format(string $format)
Definition barcode.php:90
options(array $options)
Definition barcode.php:100
option(string $option, $value)
Definition barcode.php:111