텍스트의 한 줄에 QR 코드의 두 행을 인코딩하기 위해 반자 높이, 전체 블록 및 공백을 사용하십시오. bacon/bacon-qr-code
<?php
require(__DIR__.'/vendor/autoload.php');
use BaconQrCode\Encoder\QrCode;
class HalfText extends \BaconQrCode\Renderer\Text\Plain {
protected $fullBlock = "\xE2\x96\x88";
protected $emptyBlock = "\x20";
protected $halfUpBlock = "\xE2\x96\x80";
protected $halfDnBlock = "\xE2\x96\x84";
public function render(QrCode $qrCode) {
$result = '';
$matrix = $qrCode->getMatrix();
$width = $matrix->getWidth();
// Top margin
for ($x = 0; $x < $this->margin; $x++) {
$result .= str_repeat($this->emptyBlock, $width + 2 * $this->margin) . PHP_EOL;
}
// Body
$array = $matrix->getArray();
for($y=0, $height=count($array); $y<$height; $y+=2) {
$result .= str_repeat($this->emptyBlock, $this->margin); // left margin
$oddBottom = ! key_exists($y+1, $array);
for($x=0, $width=count($array[$y]); $x<$width; $x++) {
$top = $array[$y][$x];
$bottom = $oddBottom ? 0 : $array[$y+1][$x];
switch(($top << 1) | $bottom) {
case 0:
$result .= $this->emptyBlock;
break;
case 1:
$result .= $this->halfDnBlock;
break;
case 2:
$result .= $this->halfUpBlock;
break;
case 3:
$result .= $this->fullBlock;
break;
default:
throw new BaconQrCode\Exception\OutOfBoundsException();
}
}
$result .= str_repeat($this->emptyBlock, $this->margin); // right margin
$result .= PHP_EOL;
}
// Bottom margin
for ($x = 0; $x < $this->margin; $x++) {
$result .= str_repeat($this->emptyBlock, $width + 2 * $this->margin) . PHP_EOL;
}
return $result;
}
}
// testing
use \BaconQrCode\Writer;
if($argc !== 2) {
exit(1);
}
$r = new HalfText();
$w = new Writer($r);
echo $w->writeString($argv[1]);
예 출력에 따라
예는 :
█▀▀▀▀▀█ █▄▄█ █▀▀▀▀▀█
█ ███ █ █ █ ███ █
█ ▀▀▀ █ █▄ █ █ ▀▀▀ █
▀▀▀▀▀▀▀ █ ▀ █ ▀▀▀▀▀▀▀
▀▀█ ▄█▀ ███ ▄█▀▀█▄ ██
▀▄█▀█▀▀ ▄█▀▄ ▄██▀ ▀
▀▀ ▀ ▀ ▄█▀ ██▄ ▄▄ ▀▄
█▀▀▀▀▀█ ▄▀ ▀▄ ███▀▄▀
█ ███ █ ▀▀ ▄█▄ ▄ █▀
█ ▀▀▀ █ █▀▄▄█▄ ▀█▀▀▀▀
▀▀▀▀▀▀▀ ▀ ▀▀ ▀ ▀
Woops 누군가가 이미 더 나은 PR을했다, 오, 잘.
https://github.com/Bacon/BaconQrCode/pull/25
는 PHP로 작성된,하지만 당신은 아이디어를 얻을해야하지 : https://github.com/gtanner/qrcode-terminal/blob/master/lib/main.js – Philipp
@Philipp 나는 그의 문자 시도를 . 나는 아직도 할 수 없다. – WaitMoonMan
1. https://packagist.org/packages/bacon/bacon-qr-code 2. ['\ u2584 '는 UTF8에서'\ xE2 \ x96 \ x84'입니다.] (https://codepoints.net/U+ 2584? lang = en) 3. [이스케이프를 번역 할 수 있습니다.] (https://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf -8-encoded-cha) 4. 반 높이 블록 대신 두 개의 전체 높이 블록 [및 두 개의 공백]을 사용하십시오. – Sammitch