multimode.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * multimode.php
  4. *
  5. * @created 31.01.2023
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2023 smiley
  8. * @license MIT
  9. */
  10. use chillerlan\QRCode\QRCode;
  11. use chillerlan\QRCode\QROptions;
  12. require_once __DIR__.'/../vendor/autoload.php';
  13. // make sure we run in UTF-8
  14. // ideally, this should be set in php.ini => internal_encoding/default_charset or mbstring.internal_encoding
  15. mb_internal_encoding('UTF-8');
  16. // please excuse the IDE yelling https://youtrack.jetbrains.com/issue/WI-66549
  17. $options = new QROptions;
  18. $options->imageBase64 = false;
  19. $options->connectPaths = true;
  20. $qrcode = (new QRCode($options))
  21. ->addNumericSegment('1312')
  22. ->addByteSegment("\n")
  23. ->addAlphaNumSegment('ACAB')
  24. ->addByteSegment("\n")
  25. ->addKanjiSegment('すべての警官はろくでなしです')
  26. ->addByteSegment("\n")
  27. ->addHanziSegment('所有警察都是混蛋')
  28. ->addByteSegment("\n")
  29. ->addByteSegment('https://www.bundesverfassungsgericht.de/SharedDocs/Pressemitteilungen/DE/2016/bvg16-036.html')
  30. ;
  31. $render = $qrcode->render();
  32. if(PHP_SAPI !== 'cli'){
  33. header('Content-type: image/svg+xml');
  34. if(extension_loaded('zlib')){
  35. header('Vary: Accept-Encoding');
  36. header('Content-Encoding: gzip');
  37. $render = gzencode($render, 9);
  38. }
  39. }
  40. echo $render;
  41. exit;