multimode.php 1.2 KB

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