简体   繁体   English

将base64 php字符串转换为img标记

[英]get base64 php string into img tag

Ive got a php file 'get.php' that echo's a base64 string. 我有一个php文件'get.php',它是一个base64字符串。

How would i display this as an image in another .php page? 我如何在另一个.php页面中将其显示为图像?

something like this: 这样的事情:

<img src="get.php?id=$lastid">

thanks for your help! 谢谢你的帮助!

You can do something like this: 你可以这样做:

<img src="data:image/png;base64,BASE64STRING">

but if you BASE64STRING is the output of a php, then something like this would work: 但是如果你的BASE64STRING是php的输出,那么像这样的东西会起作用:

<img src="data:image/png;base64, <?php include 'get.php?id=$lastid' ?>>

I know it may not be exactly but I hope you get the idea 我知道这可能不完全正确,但我希望你能得到这个想法

If you want to display that as an image you will need to look into GD Library and generate a run time image using a function like imagettftext() after the image has been generated, your PHP script will send a header saying this is an image something like 如果要将其显示为图像,则需要查看GD库并在生成图像后使用imagettftext()等函数生成运行时图像,PHP脚本将发送标题,说明这是图像喜欢

header( "Content-type: image/jpeg"); 

and then echo the binary data of the generate image. 然后回显生成图像的二进制数据。

I found this question for you which should help you get started, look at the accepted answer: Text on a image 我发现这个问题可以帮助你开始,看看接受的答案: 图像上的文字

No, you need to echo the output of get.php directly. 不,你需要直接回显get.php的输出。 Why don't you just include and call that function on the original page in source? 为什么不在源代码中的原始页面上包含并调用该函数? Don't forget that the base64 string needs data:image/png;base64, or similar at the beginning. 不要忘记base64字符串需要data:image/png;base64,或者类似的开头。

<?php

include_once('get.php');

echo '<img src="'.base64img($lastid).'">';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM