2011-03-08 46 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