如何显示使用PHP GD动态生成的嵌入式图像 [英] How to display an inline image generated on the fly using PHP GD

查看:59
本文介绍了如何显示使用PHP GD动态生成的嵌入式图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过使用PHP GD合并图像来动态生成图像.我想知道是否有一种方法可以在网页内显示图像,而无需将其存储在服务器上的某个位置.

I am trying the generate an image on the fly by merging images using PHP GD. I want to know if there is a way I can display the image inside my webpage without the need of storing it somewhere on server.

例如,我创建了以下代码来合并图像...

Like for example I created the following code for merging the images...

function create_image() {
   $main_image = imagecreatefrompng("images/main.png");
   $other_image = imagecreatefrompng("images/other.png");
   imagecopy($main_image, $other_image, 114, 53, 0, 0, 49, 34);
   imagepng($main_image);
   imagedestroy($other_image);
}

现在我的html代码到现在为止...

Now my html code till now was...

<div class="sidebar-avatar">
   <img src="avatar_pattern.png" class="pattern1" width="430" height="100" />
</div>

我应该如何调用php函数,以便它显示在我为其指定的div中生成的图像.

How should I call the php function so that it displays the image generated in the div I have designated for it.

更新:我发现使用了Content-type: image/png,但这意味着我将不得不在非内联的单独页面上显示图像.

Update: I found the use of Content-type: image/png but that would mean I will have to display the image on a separate page not inline.

推荐答案

使用base64_encode将其转换为Base64,并将其作为img标签中的dataURI回显!

Convert it to Base64 with base64_encode and echo it as a dataURI in an img tag !

具有数据URL的内嵌图像

这篇关于如何显示使用PHP GD动态生成的嵌入式图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆