example.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @filesource example.php
  4. * @created 10.12.2015
  5. * @author Smiley <smiley@chillerlan.net>
  6. * @copyright 2015 Smiley
  7. * @license MIT
  8. */
  9. require_once '../vendor/autoload.php';
  10. use chillerlan\QRCode\Output\QRMarkup;
  11. use chillerlan\QRCode\Output\QRMarkupOptions;
  12. use chillerlan\QRCode\QRCode;
  13. use chillerlan\QRCode\Output\QRImage;
  14. use chillerlan\QRCode\Output\QRString;
  15. use chillerlan\QRCode\Output\QRStringOptions;
  16. $data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net';
  17. #$data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
  18. #$data = 'skype://echo123';
  19. ?>
  20. <!DOCTYPE html>
  21. <html lang="en">
  22. <head>
  23. <meta charset="UTF-8"/>
  24. <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  25. <title>QRCode test</title>
  26. <style>
  27. body{
  28. margin: 0;
  29. padding: 0;
  30. }
  31. div.qrcode{
  32. margin: 0 5px;
  33. }
  34. /* row element */
  35. div.qrcode > p {
  36. margin: 0;
  37. padding: 0;
  38. height: 5px;
  39. }
  40. /* column element(s) */
  41. div.qrcode > p > b,
  42. div.qrcode > p > i {
  43. display: inline-block;
  44. width: 5px;
  45. height: 5px;
  46. }
  47. div.qrcode > p > b {
  48. background-color: #000;
  49. }
  50. div.qrcode > p > i {
  51. background-color: #fff;
  52. }
  53. </style>
  54. </head>
  55. <body>
  56. <?php
  57. // image
  58. echo '<img alt="qrcode" src="'.(new QRCode($data, new QRImage))->output().'" />';
  59. // markup - svg
  60. echo '<div>'.(new QRCode($data, new QRMarkup))->output().'</div>';
  61. // markup - html
  62. $outputOptions = new QRMarkupOptions;
  63. $outputOptions->type = QRCode::OUTPUT_MARKUP_HTML;
  64. echo '<div class="qrcode">'.(new QRCode($data, new QRMarkup($outputOptions)))->output().'</div>';
  65. // string - json
  66. echo '<pre>'.(new QRCode($data, new QRString))->output().'<pre>';
  67. // string - text
  68. $outputOptions = new QRStringOptions;
  69. $outputOptions->type = QRCode::OUTPUT_STRING_TEXT;
  70. echo '<pre>'.(new QRCode($data, new QRString($outputOptions)))->output().'</pre>';
  71. ?>
  72. </body>
  73. </html>