reflectance.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * reflectance reversal example
  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\QRMarkupSVG;
  13. use chillerlan\QRCode\QRCode;
  14. use chillerlan\QRCode\QROptions;
  15. require_once __DIR__.'/../vendor/autoload.php';
  16. $options = new QROptions;
  17. $options->outputInterface = QRMarkupSVG::class;
  18. $options->outputBase64 = false;
  19. $options->svgAddXmlHeader = false;
  20. $options->connectPaths = true;
  21. $options->drawCircularModules = false;
  22. $options->drawLightModules = true;
  23. $options->addLogoSpace = true;
  24. $options->eccLevel = EccLevel::H;
  25. $options->logoSpaceWidth = 11;
  26. $options->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. $qrcode = (new QRCode($options))->addByteSegment('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
  61. $matrix = $qrcode->getQRMatrix();
  62. $out_normal = $qrcode->renderMatrix($matrix);
  63. $out_inverted = $qrcode->renderMatrix($matrix->invert());
  64. // dump the output
  65. header('Content-type: text/html');
  66. ?>
  67. <!DOCTYPE html>
  68. <html lang="en">
  69. <head>
  70. <meta charset="UTF-8"/>
  71. <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  72. <title>QRCode Reflectance reversal Example</title>
  73. <style>
  74. #reflectance-example{
  75. width: 500px;
  76. margin: 2em auto;
  77. }
  78. #reflectance-example > svg.qrcode{
  79. margin: 1em;
  80. }
  81. </style>
  82. </head>
  83. <body>
  84. <div id="reflectance-example">
  85. <!-- embed the SVG directly -->
  86. <?php
  87. echo $out_normal;
  88. echo $out_inverted;
  89. ?>
  90. </div>
  91. </body>
  92. </html>