Built-In-Output-QRMarkupHTML.md.txt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # QRMarkupHTML
  2. [Class `QRMarkupHTML`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRMarkupHTML.php): HTML output
  3. This class is a cheap markup substitute for when SVG is not available or not an option (which was an issue before ca 2012).
  4. As a general rule: if you plan to display the QR Code in a web browser, you should be using the [SVG output](./Built-In-Output-QRMarkupSVG.md).
  5. ## Example
  6. See: [HTML example](https://github.com/chillerlan/php-qrcode/blob/main/examples/html.php)
  7. Set the options:
  8. ```php
  9. $options = new QROptions;
  10. $options->outputType = QROutputInterface::MARKUP_HTML;
  11. $options->cssClass = 'qrcode';
  12. // default values for unassigned module types
  13. $options->markupDark = '#555';
  14. $options->markupLight = '#CCC';
  15. $options->moduleValues = [
  16. // finder
  17. QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)
  18. QRMatrix::M_FINDER_DOT => '#A71111', // finder dot, dark (true)
  19. QRMatrix::M_FINDER => '#FFBFBF', // light (false)
  20. // alignment
  21. QRMatrix::M_ALIGNMENT_DARK => '#A70364',
  22. QRMatrix::M_ALIGNMENT => '#FFC9C9',
  23. ];
  24. ```
  25. Output in a HTML document (via PHP):
  26. ```php
  27. <?php
  28. $data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
  29. $out = (new QRCode($options))->render($data);
  30. header('Content-type: text/html');
  31. ?>
  32. <!DOCTYPE html>
  33. <html lang="none">
  34. <head>
  35. <meta charset="UTF-8"/>
  36. <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  37. <title>QRCode HTML Example</title>
  38. <style>
  39. div.qrcode{
  40. margin: 1em;
  41. }
  42. /* rows */
  43. div.qrcode > div {
  44. height: 10px;
  45. }
  46. /* modules */
  47. div.qrcode > div > span {
  48. display: inline-block;
  49. width: 10px;
  50. height: 10px;
  51. }
  52. </style>
  53. </head>
  54. <body>
  55. <!-- php poutput -->
  56. <?php echo $out; ?>
  57. </body>
  58. </html>
  59. ```
  60. ## Additional methods
  61. | method | return | description |
  62. |----------------------------------------------|----------|-------------------------------------------------------------------------|
  63. | (protected) `createMarkup(bool $saveToFile)` | `string` | Returns the fully parsed and rendered markup string for the given input |
  64. | (protected) `getCssClass(int $M_TYPE = 0)` | `string` | Returns a string with all css classes for the current element |
  65. ## Options that affect this module
  66. | property | type |
  67. |----------------|----------|
  68. | `$cssClass` | `string` |
  69. | `$eol` | `string` |
  70. | `$markupDark` | `string` |
  71. | `$markupLight` | `string` |
  72. ### Options that have no effect
  73. | property | reason |
  74. |------------------------|---------|
  75. | `$bgColor` | via CSS |
  76. | `$circleRadius` | N/A |
  77. | `$connectPaths` | N/A |
  78. | `$drawCircularModules` | N/A |
  79. | `$drawLightModules` | N/A |
  80. | `$excludeFromConnect` | N/A |
  81. | `$imageTransparent` | N/A |
  82. | `$keepAsSquare` | N/A |
  83. | `$outputBase64` | N/A |
  84. | `$returnResource` | N/A |
  85. | `$scale` | via CSS |