-
-
Notifications
You must be signed in to change notification settings - Fork 306
/
Copy pathsvg.php
76 lines (65 loc) · 1.94 KB
/
svg.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
/**
* SVG output example
*
* @created 21.12.2017
* @author Smiley <[email protected]>
* @copyright 2017 Smiley
* @license MIT
*
* @noinspection PhpComposerExtensionStubsInspection
*/
declare(strict_types=1);
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\QRMarkupSVG;
require_once __DIR__.'/../vendor/autoload.php';
$options = new QROptions;
$options->version = 7;
$options->outputInterface = QRMarkupSVG::class;
$options->outputBase64 = false;
// if set to false, the light modules won't be rendered
$options->drawLightModules = true;
$options->svgUseFillAttributes = false;
// draw the modules as circles isntead of squares
$options->drawCircularModules = true;
$options->circleRadius = 0.4;
// connect paths
$options->connectPaths = true;
// keep modules of these types as square
$options->keepAsSquare = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
];
// https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
$options->svgDefs = '
<linearGradient id="rainbow" x1="1" y2="1">
<stop stop-color="#e2453c" offset="0"/>
<stop stop-color="#e07e39" offset="0.2"/>
<stop stop-color="#e5d667" offset="0.4"/>
<stop stop-color="#51b95b" offset="0.6"/>
<stop stop-color="#1e72b7" offset="0.8"/>
<stop stop-color="#6f5ba7" offset="1"/>
</linearGradient>
<style><![CDATA[
.dark{fill: url(#rainbow);}
.light{fill: #eee;}
]]></style>';
try{
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
}
catch(Throwable $e){
// handle the exception in whatever way you need
exit($e->getMessage());
}
if(PHP_SAPI !== 'cli'){
header('Content-type: image/svg+xml');
if(extension_loaded('zlib')){
header('Vary: Accept-Encoding');
header('Content-Encoding: gzip');
$out = gzencode($out, 9);
}
}
echo $out;
exit;