svg.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * @created 21.12.2017
  4. * @author Smiley <smiley@chillerlan.net>
  5. * @copyright 2017 Smiley
  6. * @license MIT
  7. */
  8. namespace chillerlan\QRCodeExamples;
  9. use chillerlan\QRCode\{QRCode, QROptions};
  10. use chillerlan\QRCode\Data\QRMatrix;
  11. use chillerlan\QRCode\Common\EccLevel;
  12. require_once __DIR__.'/../vendor/autoload.php';
  13. $data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs';
  14. $gzip = true;
  15. $options = new QROptions([
  16. 'version' => 7,
  17. 'outputType' => QRCode::OUTPUT_MARKUP_SVG,
  18. 'imageBase64' => false,
  19. 'eccLevel' => EccLevel::L,
  20. 'addQuietzone' => true,
  21. // if set to true, the light modules won't be rendered
  22. 'imageTransparent' => false,
  23. // empty the default value to remove the fill* attributes from the <path> elements
  24. 'markupDark' => '',
  25. 'markupLight' => '',
  26. // draw the modules as circles isntead of squares
  27. 'svgDrawCircularModules' => true,
  28. 'svgCircleRadius' => 0.3,
  29. // keep modules of thhese types as square
  30. 'svgKeepAsSquare' => [QRMatrix::M_FINDER|QRMatrix::IS_DARK, QRMatrix::M_FINDER_DOT, QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK],
  31. // connect
  32. 'svgConnectPaths' => true,
  33. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient
  34. 'svgDefs' => '
  35. <linearGradient id="rainbow" x1="100%" y2="100%">
  36. <stop stop-color="#e2453c" offset="2.5%"/>
  37. <stop stop-color="#e07e39" offset="21.5%"/>
  38. <stop stop-color="#e5d667" offset="40.5%"/>
  39. <stop stop-color="#51b95b" offset="59.5%"/>
  40. <stop stop-color="#1e72b7" offset="78.5%"/>
  41. <stop stop-color="#6f5ba7" offset="97.5%"/>
  42. </linearGradient>
  43. <style><![CDATA[
  44. .dark{fill: url(#rainbow);}
  45. .light{fill: #eee;}
  46. ]]></style>',
  47. ]);
  48. $qrcode = (new QRCode($options))->render($data);
  49. header('Content-type: image/svg+xml');
  50. if($gzip){
  51. header('Vary: Accept-Encoding');
  52. header('Content-Encoding: gzip');
  53. $qrcode = gzencode($qrcode, 9);
  54. }
  55. echo $qrcode;