xml.php 1.8 KB

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