2011-03-08 45 views
3

嗨它保存到磁盘具有以下功能要呈现的图像,而无需使用PHP GD库

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); ?>" 
图像标签内显示图像

但不知何故,它总是呈现乱码到屏幕上,而不是我想要的结果。这是可能吗?以及如何不使用一个单独的文件,我想这留在一个函数或方法。

回答

6

您需要在单独的资源中呈现图像。在HTML文档中添加图像数据没有好方法。 (推荐data: URI的任何人都在想:这是一个可怕的想法。)

<img src="renderBusinessCard.php?param1=1&param2=2"> 
+2

+1,但我推荐使用'data:URIs';)j/k – 2011-03-08 22:48:46

+0

Thx,那么我需要这样做,谢谢。我会做的是我宁愿在一个文件夹中创建图像,然后从那里渲染它,由于应用程序的结构“长篇故事” – Roland 2011-03-09 06:30:42

0

这可能是最好保持在会话数据$细节数组,如果它不是太大。 然后调用将调用脚本并关联正确的详细信息数据。

+0

Thx,但不喜欢会话太多 – Roland 2011-03-09 06:31:34