嗨有以下功能
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);
}
我想要实现的是在图像标签内显示图像,如下所示
<img src="<?php renderBusinessCard($details); ?>"
但不知何故,它总是将乱码代码渲染到屏幕而不是我想要的结果.这是可能吗?如果不使用单独的文件,我希望它保留在一个函数或方法中.
解决方法:
您需要在单独的资源中呈现图像.没有好的方法在HTML文档中添加图像数据. (任何人都在考虑推荐数据:URI:这是一个糟糕的主意.)
<img src="renderBusinessCard.php?param1=1¶m2=2">