使用TCPDF生成仅包含字母字符的QR码时,我遇到大小问题。我的目标是:生成最长的URL(带有随机部分),但将QR码保持为最小,即21x21模块(版本1)。 文档(QRcode.com)报告说,仅使用字母数字字符集(thonky.com),URL的长度可以为25个字符,而ERC设置为L。
按预期方式使用带有25个字母数字URL的write2DBarCode会导致版本1(21x21mod)QR正常
$pdf->write2DBarcode('HTTP://SITE-COM/123456789', 'QRCODE,L', 20, 20, 40, 40, $style, 'N');
但是改用另一个25个字母数字的URL,我得到了版本2(25x25mod)的QR码,而版本1可以完成(Tested on Nayuki)
$pdf->write2DBarcode('HTTP://TXT-CH/AYAWEQYAF4A', 'QRCODE,L', 20, 70, 40, 40, $style, 'N');
我加入示例TCPDF Outputs给出的2个QR码的TCPDF输出
预先感谢您对这个精美的TCPDF库的帮助。
答案 0 :(得分:1)
简短的回答:您使用的TCPDF软件不是最佳的。即使短的一个就足够了,它也会生成一个完整的4位终结器。请与软件作者联系以解决此问题。您可以将它们链接到该线程。
因此我将您的图像裁剪为两张QR码图像,并将其提交给ZXing Decoder Online和KaarPoSoft QR Decode with debug output。
ZXing,第一个条形码:
Decode Succeeded
Raw text HTTP://SITE-COM/123456789
Raw bytes 20 83 1a a6 5f 9f d5 b4 75 3e 8d 20 48 81 23 db 91 8a 80
Barcode format QR_CODE
Parsed Result Type URI
Parsed Result HTTP://SITE-COM/123456789
ZXing,第二个条形码:
Decode Succeeded
Raw text HTTP://TXT-CH/AYAWEQYAF4A
Raw bytes 20 cb 1a a6 5f 9f d6 5e ae 82 ca 0f 21 e2 52 18 11 53 94 00 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11
Barcode format QR_CODE
Parsed Result Type URI
Parsed Result HTTP://TXT-CH/AYAWEQYAF4A
KaarPoSoft,第一个条形码:
Debug output
skew_limit=7.21875
skew=0
left=31 right=427 top=27 bottom=423
size=397
matchVersion version=1 finder0=64 finder1=64 finder2=64
matchVersion version=1 timing0=1 timing1=1 alignment=1
matchVersion version=1 format_NW =14 0 format_NESW =14 1 format = 14 ecl = 1 mask = 6
matchVersion version=1 grades(F(V)TAF): 4444->4
findModuleSize matchVersion version=1 grade=4
findModuleSize version=1 grade=4 error_correction_level=1 mask=6
getCodewords mask=6 length=26
getCodewords = 32,131,26,166,95,159,213,180,117,62,141,32,72,129,35,219,145,138,128,62,191,105,157,147,176,164
setBlocks n_blocks_first=1 n_blocks_second=0 n_blocks=1 n_block_words_first=19 n_block_words_second=0 n_block_ec_words=7 total=26
setBlocks block 0 (26): 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25
RS calculateSyndroms: No errors
correctErrors in = 32,131,26,166,95,159,213,180,117,62,141,32,72,129,35,219,145,138,128,62,191,105,157,147,176,164
correctErrors out = 32,131,26,166,95,159,213,180,117,62,141,32,72,129,35,219,145,138,128
error_grade=4
extractData bytes in (19) = 32,131,26,166,95,159,213,180,117,62,141,32,72,129,35,219,145,138,128
extractData mode = 2
extractAlphanum charcount = 16
extractData mode = 1
extractNumeric charcount = 9
extractData mode = 0
extractData data(25) = 72,84,84,80,58,47,47,83,73,84,69,45,67,79,77,47,49,50,51,52,53,54,55,56,57
KaarPoSoft,第二个条形码:
Debug output
skew_limit=7.015625
skew=1
left=21 right=417 top=30 bottom=425
size=396.5
findModuleSize matchVersion version=1 grade=0
matchVersion version=2 finder0=64 finder1=64 finder2=64
matchVersion version=2 timing0=1 timing1=1 alignment=1
matchVersion version=2 format_NW =14 0 format_NESW =14 1 format = 14 ecl = 1 mask = 6
matchVersion version=2 grades(F(V)TAF): 4444->4
findModuleSize matchVersion version=2 grade=4
findModuleSize version=2 grade=4 error_correction_level=1 mask=6
getCodewords mask=6 length=44
getCodewords = 32,203,26,166,95,159,214,94,174,130,202,15,33,226,82,24,17,83,148,0,236,17,236,17,236,17,236,17,236,17,236,17,236,17,87,194,99,197,7,184,131,204,163,52
setBlocks n_blocks_first=1 n_blocks_second=0 n_blocks=1 n_block_words_first=34 n_block_words_second=0 n_block_ec_words=10 total=44
setBlocks block 0 (44): 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43
RS calculateSyndroms: No errors
correctErrors in = 32,203,26,166,95,159,214,94,174,130,202,15,33,226,82,24,17,83,148,0,236,17,236,17,236,17,236,17,236,17,236,17,236,17,87,194,99,197,7,184,131,204,163,52
correctErrors out = 32,203,26,166,95,159,214,94,174,130,202,15,33,226,82,24,17,83,148,0,236,17,236,17,236,17,236,17,236,17,236,17,236,17
error_grade=4
extractData bytes in (34) = 32,203,26,166,95,159,214,94,174,130,202,15,33,226,82,24,17,83,148,0,236,17,236,17,236,17,236,17,236,17,236,17,236,17
extractData mode = 2
extractAlphanum charcount = 25
extractData mode = 0
extractData data(25) = 72,84,84,80,58,47,47,84,88,84,45,67,72,47,65,89,65,87,69,81,89,65,70,52,65
两个QR码在纠错或格式违反方面似乎都没有问题。
从KaarPoSoft输出中,我们可以在QR码中看到细分。
第一个条形码分为两个部分:
第二个条形码有一个段:
现在,版本1的QR码具有较低的纠错级别,可容纳19个数据代码字字节或152位。第一个条形码使用101 + 44 = 145位= 19字节(向上舍入),因此适合。第二个条形码使用151位= 19字节(向上舍入),因此适合。因此,从理论上讲,两个文本数据段列表都应适合版本1低ECC。
根据QR规范,在段列表结束后,将附加以下位:
我们来剖析实际发生的事情。将ZXing十六进制字节输出转换为二进制,并注释字段。
第一个条形码:
20 83 1a a6 5f 9f d5 b4 75 3e 8d 20 48 81 23 db 91 8a 80
0010 000010000 [88 bits] 0001 0000001001 [30 bits] 0000 000 (Total length = 152 bits)
^Mode ^Count ^Data ^Mode ^Count ^Data ^TERM ^BITPAD
第二个条形码:
20 cb 1a a6 5f 9f d6 5e ae 82 ca 0f 21 e2 52 18 11 53 94 00 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11 ec 11
0010 000011001 [138 bits] | 0000 00000 11101100 00010001 [...] (Total length = 272 bits)
^Mode ^Count ^Data | ^TERM ^BITPAD ^BYTEPAD
请注意,在第二个条形码中,在TERMinator之前的|
位置,左侧有151位。终止符通常为四个“ 0”位,但如果达到容量(152位),则可以缩短该终止符。因此,最佳终结器是一个单一的“ 0”位,因此必须没有位填充和字节填充。