dragoninasia2014 2011-01-24 21:13
浏览 49
已采纳

如何使用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);
}

Now my html code till now was...

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

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

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.

  • 写回答

3条回答 默认 最新

  • dongye1934 2011-09-09 05:33
    关注

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

    Inline Images with Data URLs

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部