Browse Source

:octocat: changed default values for QROptionsTrait::$textDark and QROptionsTrait::$textLight to ██ and ░░ respectively

smiley 2 years ago
parent
commit
52a1e5f8fb
3 changed files with 64 additions and 51 deletions
  1. 33 20
      examples/text.php
  2. 2 2
      src/QROptionsTrait.php
  3. 29 29
      tests/Output/samples/text

+ 33 - 20
examples/text.php

@@ -11,40 +11,53 @@ use chillerlan\QRCode\Data\QRMatrix;
 
 require_once __DIR__.'/../vendor/autoload.php';
 
+/**
+ * a little helper to create a proper ANSI 8-bit color escape sequence
+ *
+ * @see https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
+ * @see https://en.wikipedia.org/wiki/Block_Elements
+ *
+ * @codeCoverageIgnore
+ */
+function ansi8(string $str, int $color, bool $background = null):string{
+	$color      = max(0, min($color, 255));
+	$background = ($background === true) ? 48 : 38;
+
+	return sprintf("\x1b[%s;5;%sm%s\x1b[0m", $background, $color, $str);
+}
+
+
 $options = new QROptions([
 	'version'      => 5,
 	'outputType'   => QRCode::OUTPUT_STRING_TEXT,
 	'eccLevel'     => QRCode::ECC_L,
 	'moduleValues' => [
 		// finder
-		(QRMatrix::M_FINDER << 8)     => 'A', // dark (true)
-		(QRMatrix::M_FINDER_DOT << 8) => 'A', // dark (true)
-		QRMatrix::M_FINDER            => 'a', // light (false)
+		QRMatrix::M_FINDER_DARK    => ansi8('██', 124), // dark (true)
+		QRMatrix::M_FINDER_DOT     => ansi8('██', 124), // dark (true)
+		QRMatrix::M_FINDER         => ansi8('░░', 124), // light (false)
 		// alignment
-		(QRMatrix::M_ALIGNMENT << 8)  => 'B',
-		QRMatrix::M_ALIGNMENT         => 'b',
+		QRMatrix::M_ALIGNMENT_DARK => ansi8('██', 2),
+		QRMatrix::M_ALIGNMENT      => ansi8('░░', 2),
 		// timing
-		(QRMatrix::M_TIMING << 8)     => 'C',
-		QRMatrix::M_TIMING            => 'c',
+		QRMatrix::M_TIMING_DARK    => ansi8('██', 184),
+		QRMatrix::M_TIMING         => ansi8('░░', 184),
 		// format
-		(QRMatrix::M_FORMAT << 8)     => 'D',
-		QRMatrix::M_FORMAT            => 'd',
+		QRMatrix::M_FORMAT_DARK    => ansi8('██', 200),
+		QRMatrix::M_FORMAT         => ansi8('░░', 200),
 		// version
-		(QRMatrix::M_VERSION << 8)    => 'E',
-		QRMatrix::M_VERSION           => 'e',
+		QRMatrix::M_VERSION_DARK   => ansi8('██', 21),
+		QRMatrix::M_VERSION        => ansi8('░░', 21),
 		// data
-		(QRMatrix::M_DATA << 8)       => 'F',
-		QRMatrix::M_DATA              => 'f',
+		QRMatrix::M_DATA_DARK      => ansi8('██', 166),
+		QRMatrix::M_DATA           => ansi8('░░', 166),
 		// darkmodule
-		(QRMatrix::M_DARKMODULE << 8) => 'G',
+		QRMatrix::M_DARKMODULE     => ansi8('██', 53),
 		// separator
-		QRMatrix::M_SEPARATOR         => 'h',
+		QRMatrix::M_SEPARATOR      => ansi8('░░', 253),
 		// quietzone
-		QRMatrix::M_QUIETZONE         => 'x',
+		QRMatrix::M_QUIETZONE      => ansi8('░░', 253),
 	],
 ]);
 
-// <pre> to view it in a browser
-$qrcode = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
-
-echo '<pre style="line-height: 1;">'.$qrcode.'</pre>';
+echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');

+ 2 - 2
src/QROptionsTrait.php

@@ -140,12 +140,12 @@ trait QROptionsTrait{
 	/**
 	 * string substitute for dark
 	 */
-	protected string $textDark = '🔴';
+	protected string $textDark = '██';
 
 	/**
 	 * string substitute for light
 	 */
-	protected string $textLight = '';
+	protected string $textLight = '░░';
 
 	/**
 	 * markup substitute for dark (CSS value)

+ 29 - 29
tests/Output/samples/text

@@ -1,29 +1,29 @@
-⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕
-⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕
-⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕
-⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕
-⭕⭕⭕⭕🔴🔴🔴🔴🔴🔴🔴⭕🔴🔴⭕⭕🔴⭕🔴🔴🔴🔴🔴🔴🔴⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕⭕⭕⭕⭕🔴⭕⭕🔴⭕⭕🔴⭕🔴⭕⭕⭕⭕⭕🔴⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕🔴🔴🔴⭕🔴⭕🔴⭕🔴⭕🔴⭕🔴⭕🔴🔴🔴⭕🔴⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕🔴🔴🔴⭕🔴⭕🔴⭕⭕🔴⭕⭕🔴⭕🔴🔴🔴⭕🔴⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕🔴🔴🔴⭕🔴⭕🔴🔴🔴⭕⭕⭕🔴⭕🔴🔴🔴⭕🔴⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕⭕⭕⭕⭕🔴⭕⭕⭕⭕⭕⭕⭕🔴⭕⭕⭕⭕⭕🔴⭕⭕⭕⭕
-⭕⭕⭕⭕🔴🔴🔴🔴🔴🔴🔴⭕🔴⭕🔴⭕🔴⭕🔴🔴🔴🔴🔴🔴🔴⭕⭕⭕⭕
-⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕🔴🔴⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕
-⭕⭕⭕⭕🔴🔴🔴🔴⭕⭕🔴⭕🔴⭕🔴⭕⭕🔴⭕⭕🔴🔴🔴⭕🔴⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕⭕🔴🔴🔴⭕🔴⭕⭕🔴⭕🔴⭕⭕🔴⭕🔴🔴⭕🔴⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕🔴⭕🔴🔴🔴⭕⭕⭕🔴⭕🔴🔴🔴🔴🔴⭕⭕🔴🔴⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕🔴🔴⭕⭕⭕🔴🔴⭕🔴⭕🔴🔴⭕⭕⭕🔴⭕🔴⭕⭕⭕⭕⭕
-⭕⭕⭕⭕⭕🔴🔴⭕🔴⭕🔴⭕⭕🔴🔴🔴⭕🔴⭕⭕🔴🔴⭕🔴⭕⭕⭕⭕⭕
-⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕🔴⭕🔴⭕⭕🔴⭕🔴⭕🔴⭕🔴⭕⭕⭕⭕⭕
-⭕⭕⭕⭕🔴🔴🔴🔴🔴🔴🔴⭕⭕⭕🔴⭕⭕🔴🔴⭕🔴🔴🔴⭕⭕⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕⭕⭕⭕⭕🔴⭕⭕🔴⭕🔴🔴🔴🔴⭕⭕🔴🔴⭕⭕⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕🔴🔴🔴⭕🔴⭕⭕🔴🔴🔴⭕⭕🔴⭕⭕⭕🔴🔴🔴⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕🔴🔴🔴⭕🔴⭕🔴🔴⭕⭕⭕🔴⭕⭕🔴🔴⭕🔴⭕⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕🔴🔴🔴⭕🔴⭕🔴⭕🔴🔴⭕🔴⭕⭕🔴⭕🔴⭕⭕⭕⭕⭕⭕
-⭕⭕⭕⭕🔴⭕⭕⭕⭕⭕🔴⭕🔴🔴🔴🔴🔴⭕🔴⭕🔴🔴⭕⭕🔴⭕⭕⭕⭕
-⭕⭕⭕⭕🔴🔴🔴🔴🔴🔴🔴⭕🔴🔴⭕🔴🔴⭕⭕🔴⭕⭕⭕⭕⭕⭕⭕⭕⭕
-⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕
-⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕
-⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕
-⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕
+░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
+░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
+░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
+░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
+░░░░░░░░██████████████░░████░░░░██░░██████████████░░░░░░░░
+░░░░░░░░██░░░░░░░░░░██░░░░██░░░░██░░██░░░░░░░░░░██░░░░░░░░
+░░░░░░░░██░░██████░░██░░██░░██░░██░░██░░██████░░██░░░░░░░░
+░░░░░░░░██░░██████░░██░░██░░░░██░░░░██░░██████░░██░░░░░░░░
+░░░░░░░░██░░██████░░██░░██████░░░░░░██░░██████░░██░░░░░░░░
+░░░░░░░░██░░░░░░░░░░██░░░░░░░░░░░░░░██░░░░░░░░░░██░░░░░░░░
+░░░░░░░░██████████████░░██░░██░░██░░██████████████░░░░░░░░
+░░░░░░░░░░░░░░░░░░░░░░░░░░████░░░░░░░░░░░░░░░░░░░░░░░░░░░░
+░░░░░░░░████████░░░░██░░██░░██░░░░██░░░░██████░░██░░░░░░░░
+░░░░░░░░██░░░░██████░░██░░░░██░░██░░░░██░░████░░██░░░░░░░░
+░░░░░░░░██░░██░░██████░░░░░░██░░██████████░░░░████░░░░░░░░
+░░░░░░░░██░░████░░░░░░████░░██░░████░░░░░░██░░██░░░░░░░░░░
+░░░░░░░░░░████░░██░░██░░░░██████░░██░░░░████░░██░░░░░░░░░░
+░░░░░░░░░░░░░░░░░░░░░░░░██░░██░░░░██░░██░░██░░██░░░░░░░░░░
+░░░░░░░░██████████████░░░░░░██░░░░████░░██████░░░░░░░░░░░░
+░░░░░░░░██░░░░░░░░░░██░░░░██░░████████░░░░████░░░░░░░░░░░░
+░░░░░░░░██░░██████░░██░░░░██████░░░░██░░░░░░██████░░░░░░░░
+░░░░░░░░██░░██████░░██░░████░░░░░░██░░░░████░░██░░░░░░░░░░
+░░░░░░░░██░░██████░░██░░██░░████░░██░░░░██░░██░░░░░░░░░░░░
+░░░░░░░░██░░░░░░░░░░██░░██████████░░██░░████░░░░██░░░░░░░░
+░░░░░░░░██████████████░░████░░████░░░░██░░░░░░░░░░░░░░░░░░
+░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
+░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
+░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
+░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░