multimode.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. declare(strict_types=1);
  11. use chillerlan\QRCode\{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->outputBase64 = 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. $out = $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. $out = gzencode($out, 9);
  38. }
  39. }
  40. echo $out;
  41. exit;