Issues (4542)

config/qrcode/qrencode.php (17 issues)

1
<?php
2
/*
3
 * PHP QR Code encoder
4
 *
5
 * Main encoder classes.
6
 *
7
 * Based on libqrencode C library distributed under LGPL 2.1
8
 * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <[email protected]>
9
 *
10
 * PHP QR Code is distributed under LGPL 3
11
 * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
12
 *
13
 * This library is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU Lesser General Public
15
 * License as published by the Free Software Foundation; either
16
 * version 3 of the License, or any later version.
17
 *
18
 * This library is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21
 * Lesser General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Lesser General Public
24
 * License along with this library; if not, write to the Free Software
25
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
 */
27
28
    class QRrsblock
29
    {
30
        public $dataLength;
31
        public $data = [];
32
        public $eccLength;
33
        public $ecc = [];
34
35
        public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs)
36
        {
37
            $rs->encode_rs_char($data, $ecc);
38
39
            $this->dataLength = $dl;
40
            $this->data = $data;
41
            $this->eccLength = $el;
42
            $this->ecc = $ecc;
43
        }
44
    }
45
46
    //##########################################################################
47
48
    class QRrawcode
49
    {
50
        public $version;
51
        public $datacode = [];
52
        public $ecccode = [];
53
        public $blocks;
54
        public $rsblocks = []; //of RSblock
55
        public $count;
56
        public $dataLength;
57
        public $eccLength;
58
        public $b1;
59
60
        //----------------------------------------------------------------------
61
        public function __construct(QRinput $input)
62
        {
63
            $spec = [0, 0, 0, 0, 0];
64
65
            $this->datacode = $input->getByteStream();
0 ignored issues
show
Are you sure the assignment to $this->datacode is correct as $input->getByteStream() targeting QRinput::getByteStream() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
66
            if (is_null($this->datacode)) {
0 ignored issues
show
The condition is_null($this->datacode) is always true.
Loading history...
67
                throw new Exception('null imput string');
68
            }
69
70
            QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec);
71
72
            $this->version = $input->getVersion();
73
            $this->b1 = QRspec::rsBlockNum1($spec);
74
            $this->dataLength = QRspec::rsDataLength($spec);
75
            $this->eccLength = QRspec::rsEccLength($spec);
76
            $this->ecccode = array_fill(0, $this->eccLength, 0);
77
            $this->blocks = QRspec::rsBlockNum($spec);
78
79
            $ret = $this->init($spec);
80
            if ($ret < 0) {
81
                throw new Exception('block alloc error');
82
                return;
0 ignored issues
show
return is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
83
            }
84
85
            $this->count = 0;
86
        }
87
88
        //----------------------------------------------------------------------
89
        public function init(array $spec)
90
        {
91
            $dl = QRspec::rsDataCodes1($spec);
92
            $el = QRspec::rsEccCodes1($spec);
93
            $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
94
95
            $blockNo = 0;
96
            $dataPos = 0;
97
            $eccPos = 0;
98
            for ($i = 0; $i < QRspec::rsBlockNum1($spec); $i++) {
99
                $ecc = array_slice($this->ecccode, $eccPos);
100
                $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
0 ignored issues
show
It seems like $rs can also be of type null; however, parameter $rs of QRrsblock::__construct() does only seem to accept QRrsItem, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

100
                $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, /** @scrutinizer ignore-type */ $rs);
Loading history...
101
                $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
102
103
                $dataPos += $dl;
104
                $eccPos += $el;
105
                $blockNo++;
106
            }
107
108
            if (QRspec::rsBlockNum2($spec) == 0) {
109
                return 0;
110
            }
111
112
            $dl = QRspec::rsDataCodes2($spec);
113
            $el = QRspec::rsEccCodes2($spec);
114
            $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
115
116
            if ($rs == null) {
117
                return -1;
118
            }
119
120
            for ($i = 0; $i < QRspec::rsBlockNum2($spec); $i++) {
121
                $ecc = array_slice($this->ecccode, $eccPos);
122
                $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
123
                $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
124
125
                $dataPos += $dl;
126
                $eccPos += $el;
127
                $blockNo++;
128
            }
129
130
            return 0;
131
        }
132
133
        //----------------------------------------------------------------------
134
        public function getCode()
135
        {
136
            $ret;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ret seems to be never defined.
Loading history...
137
138
            if ($this->count < $this->dataLength) {
139
                $row = $this->count % $this->blocks;
140
                $col = $this->count / $this->blocks;
141
                if ($col >= $this->rsblocks[0]->dataLength) {
142
                    $row += $this->b1;
143
                }
144
                $ret = $this->rsblocks[$row]->data[$col];
145
            } elseif ($this->count < $this->dataLength + $this->eccLength) {
146
                $row = ($this->count - $this->dataLength) % $this->blocks;
147
                $col = ($this->count - $this->dataLength) / $this->blocks;
148
                $ret = $this->rsblocks[$row]->ecc[$col];
149
            } else {
150
                return 0;
151
            }
152
            $this->count++;
153
154
            return $ret;
155
        }
156
    }
157
158
    //##########################################################################
159
160
    class QRcode
161
    {
162
        public $version;
163
        public $width;
164
        public $data;
165
166
        //----------------------------------------------------------------------
167
        public function encodeMask(QRinput $input, $mask)
168
        {
169
            if ($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
170
                throw new Exception('wrong version');
171
            }
172
            if ($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
173
                throw new Exception('wrong level');
174
            }
175
176
            $raw = new QRrawcode($input);
177
178
            QRtools::markTime('after_raw');
179
180
            $version = $raw->version;
181
            $width = QRspec::getWidth($version);
182
            $frame = QRspec::newFrame($version);
183
184
            $filler = new FrameFiller($width, $frame);
185
            if (is_null($filler)) {
186
                return;
187
            }
188
189
            // inteleaved data and ecc codes
190
            for ($i = 0; $i < $raw->dataLength + $raw->eccLength; $i++) {
191
                $code = $raw->getCode();
192
                $bit = 0x80;
193
                for ($j = 0; $j < 8; $j++) {
194
                    $addr = $filler->next();
195
                    $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
196
                    $bit = $bit >> 1;
197
                }
198
            }
199
200
            QRtools::markTime('after_filler');
201
202
            unset($raw);
203
204
            // remainder bits
205
            $j = QRspec::getRemainder($version);
206
            for ($i = 0; $i < $j; $i++) {
207
                $addr = $filler->next();
208
                $filler->setFrameAt($addr, 0x02);
209
            }
210
211
            $frame = $filler->frame;
212
            unset($filler);
213
214
            // masking
215
            $maskObj = new QRmask();
216
            if ($mask < 0) {
217
                if (QR_FIND_BEST_MASK) {
218
                    $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
219
                } else {
220
                    $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel());
221
                }
222
            } else {
223
                $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());
224
            }
225
226
            if ($masked == null) {
227
                return;
228
            }
229
230
            QRtools::markTime('after_mask');
231
232
            $this->version = $version;
233
            $this->width = $width;
234
            $this->data = $masked;
235
236
            return $this;
237
        }
238
239
        //----------------------------------------------------------------------
240
        public function encodeInput(QRinput $input)
241
        {
242
            return $this->encodeMask($input, -1);
243
        }
244
245
        //----------------------------------------------------------------------
246
        public function encodeString8bit($string, $version, $level)
247
        {
248
            if (string == null) {
0 ignored issues
show
The constant string was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
249
                throw new Exception('empty string!');
250
                return;
0 ignored issues
show
return is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
251
            }
252
253
            $input = new QRinput($version, $level);
254
            if ($input == null) {
255
                return;
256
            }
257
258
            $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string));
0 ignored issues
show
The call to QRinput::append() has too many arguments starting with str_split($string). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

258
            /** @scrutinizer ignore-call */ 
259
            $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
259
            if ($ret < 0) {
260
                unset($input);
261
262
                return;
263
            }
264
265
            return $this->encodeInput($input);
266
        }
267
268
        //----------------------------------------------------------------------
269
        public function encodeString($string, $version, $level, $hint, $casesensitive)
270
        {
271
            if ($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
272
                throw new Exception('bad hint');
273
                return;
0 ignored issues
show
return is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
274
            }
275
276
            $input = new QRinput($version, $level);
277
            if ($input == null) {
278
                return;
279
            }
280
281
            $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
282
            if ($ret < 0) {
283
                return;
284
            }
285
286
            return $this->encodeInput($input);
287
        }
288
289
        //----------------------------------------------------------------------
290
        public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false, $back_color = 0xFFFFFF, $fore_color = 0x000000)
0 ignored issues
show
The parameter $saveandprint is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

290
        public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, /** @scrutinizer ignore-unused */ $saveandprint = false, $back_color = 0xFFFFFF, $fore_color = 0x000000)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
291
        {
292
            $enc = QRencode::factory($level, $size, $margin, $back_color, $fore_color);
293
294
            return $enc->encodePNG($text, $outfile, $saveandprint = false);
0 ignored issues
show
Are you sure the usage of $enc->encodePNG($text, $... $saveandprint = false) targeting QRencode::encodePNG() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
295
        }
296
297
        //----------------------------------------------------------------------
298
        public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4)
299
        {
300
            $enc = QRencode::factory($level, $size, $margin);
301
302
            return $enc->encode($text, $outfile);
303
        }
304
305
        //----------------------------------------------------------------------
306
        public static function eps($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false)
0 ignored issues
show
The parameter $saveandprint is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

306
        public static function eps($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, /** @scrutinizer ignore-unused */ $saveandprint = false, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
307
        {
308
            $enc = QRencode::factory($level, $size, $margin, $back_color, $fore_color, $cmyk);
309
310
            return $enc->encodeEPS($text, $outfile, $saveandprint = false);
0 ignored issues
show
Are you sure the usage of $enc->encodeEPS($text, $... $saveandprint = false) targeting QRencode::encodeEPS() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
311
        }
312
313
        //----------------------------------------------------------------------
314
        public static function svg($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint = false, $back_color = 0xFFFFFF, $fore_color = 0x000000)
0 ignored issues
show
The parameter $saveandprint is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

314
        public static function svg($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, /** @scrutinizer ignore-unused */ $saveandprint = false, $back_color = 0xFFFFFF, $fore_color = 0x000000)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
315
        {
316
            $enc = QRencode::factory($level, $size, $margin, $back_color, $fore_color);
317
318
            return $enc->encodeSVG($text, $outfile, $saveandprint = false);
0 ignored issues
show
Are you sure the usage of $enc->encodeSVG($text, $... $saveandprint = false) targeting QRencode::encodeSVG() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
319
        }
320
321
        //----------------------------------------------------------------------
322
        public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4)
323
        {
324
            $enc = QRencode::factory($level, $size, $margin);
325
326
            return $enc->encodeRAW($text, $outfile);
327
        }
328
    }
329
330
    //##########################################################################
331
332
    class FrameFiller
333
    {
334
        public $width;
335
        public $frame;
336
        public $x;
337
        public $y;
338
        public $dir;
339
        public $bit;
340
341
        //----------------------------------------------------------------------
342
        public function __construct($width, &$frame)
343
        {
344
            $this->width = $width;
345
            $this->frame = $frame;
346
            $this->x = $width - 1;
347
            $this->y = $width - 1;
348
            $this->dir = -1;
349
            $this->bit = -1;
350
        }
351
352
        //----------------------------------------------------------------------
353
        public function setFrameAt($at, $val)
354
        {
355
            $this->frame[$at['y']][$at['x']] = chr($val);
356
        }
357
358
        //----------------------------------------------------------------------
359
        public function getFrameAt($at)
360
        {
361
            return ord($this->frame[$at['y']][$at['x']]);
362
        }
363
364
        //----------------------------------------------------------------------
365
        public function next()
366
        {
367
            do {
368
                if ($this->bit == -1) {
369
                    $this->bit = 0;
370
371
                    return ['x'=>$this->x, 'y'=>$this->y];
372
                }
373
374
                $x = $this->x;
375
                $y = $this->y;
376
                $w = $this->width;
377
378
                if ($this->bit == 0) {
379
                    $x--;
380
                    $this->bit++;
381
                } else {
382
                    $x++;
383
                    $y += $this->dir;
384
                    $this->bit--;
385
                }
386
387
                if ($this->dir < 0) {
388
                    if ($y < 0) {
389
                        $y = 0;
390
                        $x -= 2;
391
                        $this->dir = 1;
392
                        if ($x == 6) {
393
                            $x--;
394
                            $y = 9;
395
                        }
396
                    }
397
                } else {
398
                    if ($y == $w) {
399
                        $y = $w - 1;
400
                        $x -= 2;
401
                        $this->dir = -1;
402
                        if ($x == 6) {
403
                            $x--;
404
                            $y -= 8;
405
                        }
406
                    }
407
                }
408
                if ($x < 0 || $y < 0) {
409
                    return;
410
                }
411
412
                $this->x = $x;
413
                $this->y = $y;
414
            } while (ord($this->frame[$y][$x]) & 0x80);
415
416
            return ['x'=>$x, 'y'=>$y];
417
        }
418
    }
419
420
    //##########################################################################
421
422
    class QRencode
423
    {
424
        public $casesensitive = true;
425
        public $eightbit = false;
426
427
        public $version = 0;
428
        public $size = 3;
429
        public $margin = 4;
430
        public $back_color = 0xFFFFFF;
431
        public $fore_color = 0x000000;
432
433
        public $structured = 0; // not supported yet
434
435
        public $level = QR_ECLEVEL_L;
436
        public $hint = QR_MODE_8;
437
438
        //----------------------------------------------------------------------
439
        public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4, $back_color = 0xFFFFFF, $fore_color = 0x000000, $cmyk = false)
440
        {
441
            $enc = new self();
442
            $enc->size = $size;
443
            $enc->margin = $margin;
444
            $enc->fore_color = $fore_color;
445
            $enc->back_color = $back_color;
446
            $enc->cmyk = $cmyk;
0 ignored issues
show
Bug Best Practice introduced by
The property cmyk does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
447
448
            switch ($level.'') {
449
                case '0':
450
                case '1':
451
                case '2':
452
                case '3':
453
                        $enc->level = $level;
454
                    break;
455
                case 'l':
456
                case 'L':
457
                        $enc->level = QR_ECLEVEL_L;
458
                    break;
459
                case 'm':
460
                case 'M':
461
                        $enc->level = QR_ECLEVEL_M;
462
                    break;
463
                case 'q':
464
                case 'Q':
465
                        $enc->level = QR_ECLEVEL_Q;
466
                    break;
467
                case 'h':
468
                case 'H':
469
                        $enc->level = QR_ECLEVEL_H;
470
                    break;
471
            }
472
473
            return $enc;
474
        }
475
476
        //----------------------------------------------------------------------
477
        public function encodeRAW($intext, $outfile = false)
0 ignored issues
show
The parameter $outfile is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

477
        public function encodeRAW($intext, /** @scrutinizer ignore-unused */ $outfile = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
478
        {
479
            $code = new QRcode();
480
481
            if ($this->eightbit) {
482
                $code->encodeString8bit($intext, $this->version, $this->level);
483
            } else {
484
                $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
485
            }
486
487
            return $code->data;
488
        }
489
490
        //----------------------------------------------------------------------
491
        public function encode($intext, $outfile = false)
492
        {
493
            $code = new QRcode();
494
495
            if ($this->eightbit) {
496
                $code->encodeString8bit($intext, $this->version, $this->level);
497
            } else {
498
                $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
499
            }
500
501
            QRtools::markTime('after_encode');
502
503
            if ($outfile !== false) {
504
                file_put_contents($outfile, implode("\n", QRtools::binarize($code->data)));
505
            } else {
506
                return QRtools::binarize($code->data);
507
            }
508
        }
509
510
        //----------------------------------------------------------------------
511
        public function encodePNG($intext, $outfile = false, $saveandprint = false)
512
        {
513
            try {
514
                ob_start();
515
                $tab = $this->encode($intext);
516
                $err = ob_get_contents();
517
                ob_end_clean();
518
519
                if ($err != '') {
520
                    QRtools::log($outfile, $err);
521
                }
522
523
                $maxSize = (int) (QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $this->margin));
524
525
                QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin, $saveandprint, $this->back_color, $this->fore_color);
526
            } catch (Exception $e) {
527
                QRtools::log($outfile, $e->getMessage());
528
            }
529
        }
530
531
        //----------------------------------------------------------------------
532
        public function encodeEPS($intext, $outfile = false, $saveandprint = false)
533
        {
534
            try {
535
                ob_start();
536
                $tab = $this->encode($intext);
537
                $err = ob_get_contents();
538
                ob_end_clean();
539
540
                if ($err != '') {
541
                    QRtools::log($outfile, $err);
542
                }
543
544
                $maxSize = (int) (QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $this->margin));
545
546
                QRvect::eps($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin, $saveandprint, $this->back_color, $this->fore_color, $this->cmyk);
547
            } catch (Exception $e) {
548
                QRtools::log($outfile, $e->getMessage());
549
            }
550
        }
551
552
        //----------------------------------------------------------------------
553
        public function encodeSVG($intext, $outfile = false, $saveandprint = false)
554
        {
555
            try {
556
                ob_start();
557
                $tab = $this->encode($intext);
558
                $err = ob_get_contents();
559
                ob_end_clean();
560
561
                if ($err != '') {
562
                    QRtools::log($outfile, $err);
563
                }
564
565
                $maxSize = (int) (QR_PNG_MAXIMUM_SIZE / (count($tab) + 2 * $this->margin));
566
567
                QRvect::svg($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin, $saveandprint, $this->back_color, $this->fore_color);
568
            } catch (Exception $e) {
569
                QRtools::log($outfile, $e->getMessage());
570
            }
571
        }
572
    }
573