QRStringText.md.txt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # QRStringText
  2. [Class `QRStringText`](https://github.com/chillerlan/php-qrcode/blob/main/src/Output/QRStringText.php):
  3. render in a CLI console, using [ANSI colors](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) and [block elements](https://en.wikipedia.org/wiki/Block_Elements).
  4. ## Example
  5. See: [plaintext example](https://github.com/chillerlan/php-qrcode/blob/main/examples/text.php)
  6. ```php
  7. $options = new QROptions;
  8. $options->outputInterface = QRStringText::class;
  9. $options->eol = "\n";
  10. // add some space on the line start
  11. $options->textLineStart = str_repeat(' ', 6);
  12. // default values for unassigned module types
  13. $options->textDark = QRStringText::ansi8('██', 253);
  14. $options->textLight = QRStringText::ansi8('░░', 253);
  15. $options->moduleValues = [
  16. QRMatrix::M_FINDER_DARK => QRStringText::ansi8('██', 124),
  17. QRMatrix::M_FINDER => QRStringText::ansi8('░░', 124),
  18. QRMatrix::M_FINDER_DOT => QRStringText::ansi8('██', 124),
  19. QRMatrix::M_ALIGNMENT_DARK => QRStringText::ansi8('██', 2),
  20. QRMatrix::M_ALIGNMENT => QRStringText::ansi8('░░', 2),
  21. QRMatrix::M_VERSION_DARK => QRStringText::ansi8('██', 21),
  22. QRMatrix::M_VERSION => QRStringText::ansi8('░░', 21),
  23. ];
  24. ```
  25. Output:
  26. ```php
  27. $data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
  28. $qrcode = (new QRCode($options))->render($data);
  29. echo "\n\n$qrcode\n\n";
  30. ```
  31. ## Additional methods
  32. | method | return | description |
  33. |-----------------------------------------------------------|----------|---------------------------------------------------------------------|
  34. | `ansi8(string $str, int $color, bool $background = null)` | `string` | a little helper to create a proper ANSI 8-bit color escape sequence |
  35. ## Options that affect this class
  36. | property | type |
  37. |-------------------|----------|
  38. | `$eol` | `string` |
  39. | `$textDark` | `string` |
  40. | `$textLight` | `string` |
  41. | `$textLineStart` | `string` |