reflectance.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\{QRCode, QROptions};
  11. use chillerlan\QRCode\Common\EccLevel;
  12. use chillerlan\QRCode\Data\QRMatrix;
  13. use chillerlan\QRCode\Output\QRMarkupSVG;
  14. require_once __DIR__.'/../vendor/autoload.php';
  15. $options = new QROptions;
  16. $options->outputInterface = QRMarkupSVG::class;
  17. $options->outputBase64 = false;
  18. $options->svgAddXmlHeader = false;
  19. $options->connectPaths = true;
  20. $options->drawCircularModules = false;
  21. $options->drawLightModules = true;
  22. $options->addLogoSpace = true;
  23. $options->eccLevel = EccLevel::H;
  24. $options->logoSpaceWidth = 11;
  25. $options->moduleValues = [
  26. // finder
  27. QRMatrix::M_FINDER_DARK => '#555', // dark (true)
  28. QRMatrix::M_FINDER => '#ccc', // light (false)
  29. QRMatrix::M_FINDER_DOT => '#555',
  30. QRMatrix::M_FINDER_DOT_LIGHT => '#ccc',
  31. // alignment
  32. QRMatrix::M_ALIGNMENT_DARK => '#555',
  33. QRMatrix::M_ALIGNMENT => '#ccc',
  34. // timing
  35. QRMatrix::M_TIMING_DARK => '#555',
  36. QRMatrix::M_TIMING => '#ccc',
  37. // format
  38. QRMatrix::M_FORMAT_DARK => '#555',
  39. QRMatrix::M_FORMAT => '#ccc',
  40. // version
  41. QRMatrix::M_VERSION_DARK => '#555',
  42. QRMatrix::M_VERSION => '#ccc',
  43. // data
  44. QRMatrix::M_DATA_DARK => '#555',
  45. QRMatrix::M_DATA => '#ccc',
  46. // darkmodule
  47. QRMatrix::M_DARKMODULE_LIGHT => '#ccc',
  48. QRMatrix::M_DARKMODULE => '#555',
  49. // separator
  50. QRMatrix::M_SEPARATOR_DARK => '#555',
  51. QRMatrix::M_SEPARATOR => '#ccc',
  52. // quietzone
  53. QRMatrix::M_QUIETZONE_DARK => '#555',
  54. QRMatrix::M_QUIETZONE => '#ccc',
  55. // logo space
  56. QRMatrix::M_LOGO_DARK => '#555',
  57. QRMatrix::M_LOGO => '#ccc',
  58. ];
  59. $qrcode = (new QRCode($options))->addByteSegment('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
  60. $matrix = $qrcode->getQRMatrix();
  61. $out_normal = $qrcode->renderMatrix($matrix);
  62. $out_inverted = $qrcode->renderMatrix($matrix->invert());
  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 $out_normal;
  87. echo $out_inverted;
  88. ?>
  89. </div>
  90. </body>
  91. </html>