svg.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @created 21.12.2017
  4. * @author Smiley <smiley@chillerlan.net>
  5. * @copyright 2017 Smiley
  6. * @license MIT
  7. *
  8. * @noinspection PhpComposerExtensionStubsInspection
  9. */
  10. use chillerlan\QRCode\{QRCode, QROptions};
  11. use chillerlan\QRCode\Data\QRMatrix;
  12. require_once __DIR__.'/../vendor/autoload.php';
  13. $gzip = true;
  14. $options = new QROptions([
  15. 'version' => 7,
  16. 'outputType' => QRCode::OUTPUT_MARKUP_SVG,
  17. 'imageBase64' => false,
  18. 'eccLevel' => QRCode::ECC_L,
  19. # 'svgViewBoxSize' => 530,
  20. 'addQuietzone' => true,
  21. 'svgOpacity' => 1.0,
  22. 'svgDefs' => '
  23. <linearGradient id="g2">
  24. <stop offset="0%" stop-color="#39F" />
  25. <stop offset="100%" stop-color="#F3F" />
  26. </linearGradient>
  27. <linearGradient id="g1">
  28. <stop offset="0%" stop-color="#F3F" />
  29. <stop offset="100%" stop-color="#39F" />
  30. </linearGradient>
  31. <style>rect{shape-rendering:crispEdges}</style>',
  32. 'moduleValues' => [
  33. // finder
  34. QRMatrix::M_FINDER_DARK => 'url(#g1)', // dark (true)
  35. QRMatrix::M_FINDER_DOT => 'url(#g1)',
  36. QRMatrix::M_FINDER => '#fff', // light (false)
  37. // alignment
  38. QRMatrix::M_ALIGNMENT_DARK => 'url(#g1)',
  39. QRMatrix::M_ALIGNMENT => '#fff',
  40. // timing
  41. QRMatrix::M_TIMING_DARK => 'url(#g1)',
  42. QRMatrix::M_TIMING => '#fff',
  43. // format
  44. QRMatrix::M_FORMAT_DARK => 'url(#g1)',
  45. QRMatrix::M_FORMAT => '#fff',
  46. // version
  47. QRMatrix::M_VERSION_DARK => 'url(#g1)',
  48. QRMatrix::M_VERSION => '#fff',
  49. // data
  50. QRMatrix::M_DATA_DARK => 'url(#g2)',
  51. QRMatrix::M_DATA => '#fff',
  52. // darkmodule
  53. QRMatrix::M_DARKMODULE => 'url(#g1)',
  54. // separator
  55. QRMatrix::M_SEPARATOR => '#fff',
  56. // quietzone
  57. QRMatrix::M_QUIETZONE => '#fff',
  58. ],
  59. ]);
  60. $qrcode = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
  61. header('Content-type: image/svg+xml');
  62. if($gzip === true){
  63. header('Vary: Accept-Encoding');
  64. header('Content-Encoding: gzip');
  65. $qrcode = gzencode($qrcode , 9);
  66. }
  67. echo $qrcode;