Re: [請益] HELP!!! 關於 FPDF 崁入圖片>"<

看板PHP作者 (就是喜歡找「茶」)時間15年前 (2010/10/18 12:51), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《teaRsis (就是喜歡找「茶」)》之銘言: : Q:請問如何在FPDF中支援外連圖片的崁入? : 目前在做一個系統 : 經過ABC步驟後可以產生結果D : D的開頭有用 session_start(); : 以擷取ABC傳的值來顯示結果 : D中有做一個按鈕「存成PDF」 : 是把D的結果重整後透過FPDF來轉存PDF : D的顯示結果我有使用GOOGLE的API : http://is.gd/g4xmU : 點選以上網址會變為原本的網址 : http://chart.apis.google.com/chart?xxxxxxbalabala : 它是個PNG檔  但結尾不是PNG : 重點來了 : FPDF中要崁入圖片 : 是使用以下語法 : $pdf->Image('chart.png', 5, 30, 60, 50); : 但是它無法支援外連圖片 : 我有想過使用暫存檔將圖片強制崁入 : 而且那一串長長的網址也不是PNG結尾 : 好像不太行的說 : 不知各位高手可否提供一些意見 : 謝謝!

10/17 00:11,
把圖片抓下來另存...
10/17 00:11

10/17 00:12,
看你是要用file_get_contents, curl, wget都可以
10/17 00:12
我上網查到資料 http://phorum.study-area.org/index.php?topic=61508.0 按照裡面方式寫一個簡單PHP header("Content-type: image/png"); $url="http://chart.apis.google.com/chart?cht=gom&chd=t:100&chl=0&chs=340x230"; $picture = file_get_contents($url); echo $picture; 可以在網頁上印出圖片 不過把他寫到FPDF的網頁中就還是印不出來 <? define('FPDF_FONTPATH',"fpdi134/font/"); //引入函式庫 // require("fpdi134/fpdf.php"); require_once ('fpdi134/fpdf.php'); require_once ('fpdi134/fpdf_tpl.php'); require_once ('fpdi134/chinese-unicode.php'); require_once ('fpdi134/fpdi.php'); header("Content-type: image/png"); $url="http://chart.apis.google.com/chart?cht=gom&chd=t:100&chl=0&chs=340x230"; $picture = file_get_contents($url); $pdf=new PDF_Unicode(); $pdf->Open(); $pdf->SetTitle("檢測結果");//文件標題 $pdf->SetAuthor("NCKUID");//文件作者 $pdf->AddPage(); $pdf->SetAutoPageBreak(true,10); $pdf->AddUniCNShwFont('uni'); $pdf->Image($picture,45,4,19.5,0,'png'); $filename = "test.pdf";//pdf檔名 //header header("Content-type:application/pdf"); header("Content-Disposition:attachment;filename=$filename"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); header("Pragma: public"); $pdf->Output("test.pdf", 'D');//產生下載檔 ?> 但是他會出現錯誤訊息:無法顯示錯誤的圖片 一定要存到資料庫在取出才行嗎?? 關於存圖片到資料庫 網路上的教學都是用 upload 一個桌面上的檔案 http://forum.twbts.com/thread-581-1-1.html 不知道怎樣可以改成上傳外連的圖片?? 高手們麻煩給些建議 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.116.134.139 ※ 編輯: teaRsis 來自: 140.116.134.139 (10/18 12:52) ※ 編輯: teaRsis 來自: 140.116.134.139 (10/18 12:53)

10/18 13:25, , 1F
送了兩個 Header ?.. 先搞清楚抓圖片下來的作法.
10/18 13:25, 1F

10/18 15:56, , 2F
我沒看你那個pdf的manual不過顯然他要的參數是"檔名"
10/18 15:56, 2F

10/18 15:56, , 3F
而你把圖片的binary內容丟給他 想當然是不會成功的
10/18 15:56, 3F

10/18 15:57, , 4F
請把binary內容存成本地端檔案再傳檔名給pdf class
10/18 15:57, 4F
文章代碼(AID): #1Ckz9CMB (PHP)
討論串 (同標題文章)
文章代碼(AID): #1Ckz9CMB (PHP)