xml.php 1.7 KB

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