2010-10-23 74 views
0

我正在一個腳本中,我必須根據給定的文本創建一個圖像。在php中的圖像處理和獲得PDFof處理的圖像

基本上我必須將這些文本放置在生成圖像的各個位置。

直到我的工作完成。以下是該代碼。

header ("Content-type: image/jpeg"); 
$handle = imagecreate(415, 588) or die ("Cannot Create image"); 

$inven_tory=imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT'].'/thumb/editor/text_letter.jpg'); 
imagecopymerge($handle,$inven_tory,0,0,0,0,415,588,100); 

$bg_color = imagecolorallocate ($handle, 255, 255, 255); // 0 -255 
$txt_color = imagecolorallocate ($handle, 0, 0, 0); 


// The first parameter is our handle, then font size, rotation, starting X, starting Y, text color, font, and finally our text. 
imagettftext($handle, 15, 0, 10, 25, $txt_color, "fonts/" . $font, wordwrap($text1, 35, "\n", true)); 

// The first parameter is our handle, then font size, rotation, starting X, starting Y, text color, font, and finally our text. 
imagettftext($handle, 20, 0, 40, 120, $txt_color, "fonts/" . $font, wordwrap($text2, 13, "\n", true)); 

// The first parameter is our handle, then font size, rotation, starting X, starting Y, text color, font, and finally our text. 
imagettftext($handle, 15, 0, 10, 500, $txt_color, "fonts/" . $font, wordwrap($text3, 40, "\n", true)); 

imagejpeg($handle); 

圖片正在從本頁面正確創建。現在我將這個生成的圖像放在PDF中,並讓用戶保存該PDF。我怎樣才能做到這一點?如果你不清楚,請告訴我。

回答

0

我會嘗試使用exec()的wkhtmltodpf。

0

如果你是一個Linux服務器與ImageMagick的安裝,你可以這樣做:你打算如何創建PDF

exec("convert foo.jpg bar.pdf"); 
0

你如何放置在PDF圖像依賴。有擴展和PHP類,允許您直接創建PDF(CPDF,FPDF,TCPDF)。還有一些類和程序允許您從HTML文檔創建PDF。 PDF類爲您提供更精確的控制,HTML到PDF類使它更易於使用,因爲大多數PHP開發人員已經在某種程度上已經瞭解了HTML。你的情況很簡單,我傾向於使用PDF生成類。

您不指定如何獲取$ text1,$ text2和$ text3的值。據推測它們是由用戶提供的。所以你想要的是一個收集用戶輸入並創建PDF的中間PHP。然後,您使用完整的URL引用圖像生成PHP。像下面的內容會(使用EZPDF + CPDF)工作:

<?php 
include ('class.ezpdf.php'); 
$pdf = new Cezpdf(); 
$pdf->ezImage('http://example.com/image.php?text1='.urlencode($text1)); 
$pdf->ezStream(); 
?> 

我通常與DOMPDF,其中HTML文檔轉換爲PDF文檔工作。使用這個庫的情況也是如此簡單:

<?php 
require_once('dompdf_config.inc.php'); 
$dompdf = new DOMPDF(); 
$dompdf->load_html('http://example.com/image.php?text1='.urlencode($text1)); 
$dompdf->render(); 
$dompdr->stream(); 
?>