example.php 1.7 KB

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