我尝试在现有图像和不存在的图像上使用示例代码。 两种情况都失败了,后者没有生成图像。
$renderer = new \BaconQrCode\Renderer\Image\Png();
$renderer->setHeight(256);
$renderer->setWidth(256);
$writer = new \BaconQrCode\Writer($renderer);
$writer->writeFile('Hello World!', 'qrcode.png');
然后我想我可以写字符串而不是写入文件但是当我回声我仍然没有得到图像
`
$renderer = new \BaconQrCode\Renderer\Image\Png();
$renderer->setHeight(256);
$renderer->setWidth(256);
$writer = new \BaconQrCode\Writer($renderer);
$str= $writer->writeString('Hello World!');
header('Content-Type:image/png');
echo $str;`
我得到以下代码
�PNG IHDR�?1IDATx����n�0A'����kP!��؝9��������~������' �4�&�@�Hi M� �4�&�@�Hi M� �4�&�@�Hi M� �4�&�@�Hi M� �4�&�@�Hi M� �4����x�^���3:|������u�+W�_u?O��9�p�'��4�&�@�Hi#�W�Z'^��?m=������|�Hi M� �4�6zpeպ�u�U�럾N?����<Hi M� �4�&Ҏ����@�'i M� �4�&�@�9�F�� ��<Hi M� �4�&Ҏ�L[/�v?w�~�?� @�Hi M� �4�6z0�|�?�>
~A | !M 4 &amp; @ H * } M 4 &amp; @ H S_ w' @ HiM 4 6b u Ͽ I &amp; @ HiM ~< em> u Lx &lt; ^ iM 4 &amp; F V ǯz ʴu s Us Y Q 0 &amp; @ Him 9 U w |J 4 &amp; @ H18 ) ㅎ M 4 &amp; @ڈ9 v G &gt;E ̓M@ HiM \ &lt; 'iM 4 &amp; @ 9 = ) 'iM 4 &amp; @ڑs iv ? ? 'iM 4 &amp; @ 9 FO { j&gt;P 3x &amp; @ HiM 98e yչ _ sw &gt; 4 &amp; @ Him kv OX F HiM 4 5y v M 4 &amp; @ HiM 4 &amp; @ HiM 4 &amp; @ HiM 4 &amp; @ HiM 4 &amp; @ HiM mF sE }IEND B�
有什么问题?
任何帮助?
答案 0 :(得分:1)
如果将writeString的输出编码为base64,则可以使用它以html显示base64图像。
$renderer = new ImageRenderer(
new RendererStyle(200),
new ImagickImageBackEnd()
);
$writer = new Writer($renderer);
$qr_image = base64_encode($writer->writeString($string));
并将其显示为这样的图像。
<img src="data:image/png;base64, <?php echo $qr_image; ?> " />
答案 1 :(得分:0)
我最终决定使用包simpleqr-code。 链接到这里:https://www.simplesoftware.io/docs/simple-qrcode