reflectance.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * reflectance.php
  4. *
  5. * @created 13.07.2023
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2023 smiley
  8. * @license MIT
  9. */
  10. use chillerlan\QRCode\Common\EccLevel;
  11. use chillerlan\QRCode\Data\QRMatrix;
  12. use chillerlan\QRCode\Output\QROutputInterface;
  13. use chillerlan\QRCode\QRCode;
  14. use chillerlan\QRCode\QROptions;
  15. require_once __DIR__.'/../vendor/autoload.php';
  16. $options = new QROptions([
  17. 'outputType' => QROutputInterface::MARKUP_SVG,
  18. 'imageBase64' => false,
  19. 'svgAddXmlHeader' => false,
  20. 'connectPaths' => true,
  21. 'drawCircularModules' => false,
  22. 'drawLightModules' => true,
  23. 'addLogoSpace' => true,
  24. 'eccLevel' => EccLevel::H,
  25. 'logoSpaceWidth' => 11,
  26. 'moduleValues' => [
  27. // finder
  28. QRMatrix::M_FINDER_DARK => '#555', // dark (true)
  29. QRMatrix::M_FINDER => '#ccc', // light (false)
  30. QRMatrix::M_FINDER_DOT => '#555',
  31. QRMatrix::M_FINDER_DOT_LIGHT => '#ccc',
  32. // alignment
  33. QRMatrix::M_ALIGNMENT_DARK => '#555',
  34. QRMatrix::M_ALIGNMENT => '#ccc',
  35. // timing
  36. QRMatrix::M_TIMING_DARK => '#555',
  37. QRMatrix::M_TIMING => '#ccc',
  38. // format
  39. QRMatrix::M_FORMAT_DARK => '#555',
  40. QRMatrix::M_FORMAT => '#ccc',
  41. // version
  42. QRMatrix::M_VERSION_DARK => '#555',
  43. QRMatrix::M_VERSION => '#ccc',
  44. // data
  45. QRMatrix::M_DATA_DARK => '#555',
  46. QRMatrix::M_DATA => '#ccc',
  47. // darkmodule
  48. QRMatrix::M_DARKMODULE_LIGHT => '#ccc',
  49. QRMatrix::M_DARKMODULE => '#555',
  50. // separator
  51. QRMatrix::M_SEPARATOR_DARK => '#555',
  52. QRMatrix::M_SEPARATOR => '#ccc',
  53. // quietzone
  54. QRMatrix::M_QUIETZONE_DARK => '#555',
  55. QRMatrix::M_QUIETZONE => '#ccc',
  56. // logo space
  57. QRMatrix::M_LOGO_DARK => '#555',
  58. QRMatrix::M_LOGO => '#ccc',
  59. ],
  60. ]);
  61. $qrcode = (new QRCode($options))->addByteSegment('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
  62. $matrix = $qrcode->getQRMatrix();
  63. // dump the output
  64. header('Content-type: text/html');
  65. ?>
  66. <!DOCTYPE html>
  67. <html lang="en">
  68. <head>
  69. <meta charset="UTF-8"/>
  70. <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  71. <title>QRCode Reflectance reversal Example</title>
  72. <style>
  73. #reflectance-example{
  74. width: 500px;
  75. margin: 2em auto;
  76. }
  77. #reflectance-example > svg.qrcode{
  78. margin: 1em;
  79. }
  80. </style>
  81. </head>
  82. <body>
  83. <div id="reflectance-example">
  84. <!-- embed the SVG directly -->
  85. <?php
  86. echo $qrcode->renderMatrix($matrix);
  87. echo $qrcode->renderMatrix($matrix->invert());
  88. ?>
  89. </div>
  90. </body>
  91. </html>
  92. <?php
  93. exit;