xml.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * XML output example (not a meme)
  4. *
  5. * @created 02.05.2024
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2024 smiley
  8. * @license MIT
  9. */
  10. use chillerlan\QRCode\Data\QRMatrix;
  11. use chillerlan\QRCode\{QRCode, QROptions};
  12. use chillerlan\QRCode\Output\QRMarkupXML;
  13. require_once __DIR__.'/../vendor/autoload.php';
  14. $options = new QROptions;
  15. $options->version = 7;
  16. $options->outputInterface = QRMarkupXML::class;
  17. $options->outputBase64 = false;
  18. $options->drawLightModules = false;
  19. // assign an XSLT stylesheet
  20. $options->xmlStylesheet = './qrcode.style.xsl';
  21. $options->moduleValues = [
  22. // finder
  23. QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)
  24. QRMatrix::M_FINDER_DOT => '#A71111', // finder dot, dark (true)
  25. QRMatrix::M_FINDER => '#FFBFBF', // light (false)
  26. // alignment
  27. QRMatrix::M_ALIGNMENT_DARK => '#A70364',
  28. QRMatrix::M_ALIGNMENT => '#FFC9C9',
  29. // timing
  30. QRMatrix::M_TIMING_DARK => '#98005D',
  31. QRMatrix::M_TIMING => '#FFB8E9',
  32. // format
  33. QRMatrix::M_FORMAT_DARK => '#003804',
  34. QRMatrix::M_FORMAT => '#CCFB12',
  35. // version
  36. QRMatrix::M_VERSION_DARK => '#650098',
  37. QRMatrix::M_VERSION => '#E0B8FF',
  38. // data
  39. QRMatrix::M_DATA_DARK => '#4A6000',
  40. QRMatrix::M_DATA => '#ECF9BE',
  41. // darkmodule
  42. QRMatrix::M_DARKMODULE => '#080063',
  43. // separator
  44. QRMatrix::M_SEPARATOR => '#DDDDDD',
  45. // quietzone
  46. QRMatrix::M_QUIETZONE => '#DDDDDD',
  47. ];
  48. try{
  49. $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
  50. }
  51. catch(Throwable $e){
  52. // handle the exception in whatever way you need
  53. exit($e->getMessage());
  54. }
  55. if(PHP_SAPI !== 'cli'){
  56. header('Content-type: '.QRMarkupXML::MIME_TYPE);
  57. }
  58. echo $out;
  59. exit;