php - 使用 base64 php 将字符串转换为图像

我有一个字符串,我需要使用 php 将其转换为 base64 图像,因为我的控制器用于系统的多个地方,所以我不想在谷歌图表或 JS 中转换它。

$string = '00020101021226930014br.gov.bcb.pix2571api-h.developer.btgpactual.com/v1/p/v2/50436e18635640a4a2ee3b30fab4035e5204000053039865802BR5925ZAZ TECNOLOGIA FINANCEIRA6013FLORIANOPOLIS61088807015062070503***6304C2FD';

<img src="data:image/png;base64,<?= $string ?>" id="imageQRCode" alt="QR Code" class="qrcodeImg"/>

回答1

如果您想将以下字符串转换为 base64,您可以使用 base64 https://www.php.net/manual/en/function.base64-encode.php (base64_encode()) 或者如果您想从 URL 下载图像并将其转换为 base64,您可以可以使用此代码:

$url = 'address to the image url';
$image = file_get_contents($url);
$base64 = base64_encode($image);

<img src="data:image/png;base64,<?= $base64 ?>" id="imageQRCode" alt="QR Code" class="qrcodeImg"/>

相似文章

lua - 解密名为 LuaT 的新 lua 脚本

任何人都可以帮助解密这个lua脚本吗?通常在luaR上,我可以通过将ENV更改为打印来解密它,但这是LuaT,因此文本保持加密。多谢。key=[[Xaza]];oweofjjrgaqdajekhsiv...

随机推荐

最新文章