本文介绍了想要渲染图像而不使用PHP GD lib将其保存到磁盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,具有以下功能
function renderBusinessCard($details){
//Getting the template for the business card
$filename = Templates::model()->getTemplateFileName($details['BusinessCards']['dp_id']);
header("Content-type: image/jpeg");
$image = $_SERVER['DOCUMENT_ROOT'].'resources/templates/'.$filename;
// header("Content-Type: image/jpeg");
//Getting the width and height of the image
list($width,$height) = getimagesize($image);
//echo $width;die;
//Creating a copy of a loaded image
$create = imagecreatefromjpeg($image);
//Creating a blank template to work from
$template = imagecreatetruecolor($width,$height);
imagecopyresized($template, $create, 0, 0, 0, 0, $width, $height, $width, $height);
imagejpeg($template, null, 100);
}
我想要实现的是在图像标签中显示图像,如下所示:
What I want to achieve is to display the image within an image tag like the following
<img src="<?php renderBusinessCard($details); ?>"
,但是总会以某种方式在屏幕上呈现乱码,而不是我想要的结果.这是可能吗?以及如何在不使用单独文件的情况下,将其保留在函数或方法中.
but somehow it's always rendering garbled code to the screen and not the result I want. Is this at all possible? And how without using a seperate file, I want this to remain within a function or method.
推荐答案
您需要在单独的资源中渲染图像.没有在HTML文档中添加图像数据的好方法. (有人想到推荐data:
URI:这是一个糟糕的主意.)
You need to render the image in a separate resource. There is no good way of adding the image data inside the HTML document. (Anybody thinking of recommending data:
URIs: It's a terrible idea.)
<img src="renderBusinessCard.php?param1=1¶m2=2">
这篇关于想要渲染图像而不使用PHP GD lib将其保存到磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!