example.php 2.0 KB

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