svg.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. *
  4. * @filesource svg.php
  5. * @created 21.12.2017
  6. * @author Smiley <smiley@chillerlan.net>
  7. * @copyright 2017 Smiley
  8. * @license MIT
  9. */
  10. namespace chillerlan\QRCodeExamples;
  11. use chillerlan\QRCode\{QRCode, QROptions};
  12. require_once __DIR__.'/../vendor/autoload.php';
  13. $data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
  14. $options = new QROptions([
  15. 'version' => 20,
  16. 'outputType' => QRCode::OUTPUT_MARKUP_SVG,
  17. 'eccLevel' => QRCode::ECC_L,
  18. 'scale' => 5,
  19. 'addQuietzone' => true,
  20. 'svgOpacity' => 0.8,
  21. 'svgDefs' => '
  22. <linearGradient id="g2">
  23. <stop offset="0%" stop-color="#39F" />
  24. <stop offset="100%" stop-color="#F3F" />
  25. </linearGradient>
  26. <linearGradient id="g1">
  27. <stop offset="0%" stop-color="#F3F" />
  28. <stop offset="100%" stop-color="#39F" />
  29. </linearGradient>
  30. <style>rect{shape-rendering:crispEdges}</style>',
  31. 'moduleValues' => [
  32. // finder
  33. 1536 => 'url(#g1)', // dark (true)
  34. 6 => '#eee', // light (false)
  35. // alignment
  36. 2560 => 'url(#g1)',
  37. 10 => '#eee',
  38. // timing
  39. 3072 => 'url(#g1)',
  40. 12 => '#eee',
  41. // format
  42. 3584 => 'url(#g1)',
  43. 14 => '#eee',
  44. // version
  45. 4096 => 'url(#g1)',
  46. 16 => '#eee',
  47. // data
  48. 1024 => 'url(#g2)',
  49. 4 => '#eee',
  50. // darkmodule
  51. 512 => 'url(#g1)',
  52. // separator
  53. 8 => '#eee',
  54. // quietzone
  55. 18 => '#eee',
  56. ],
  57. ]);
  58. #header('Content-type: image/svg+xml');
  59. echo (new QRCode($options))->render($data);