2013-05-10 50 views
1

我在創建圖像和在Kohana上寫入文本時遇到了一些問題。 我的代碼工作正常,如果我使用一個簡單的PHP,但我不能integrate它在Kohana框架控制器和操作。 當我在做什麼,在它的行動我retruns一個奇怪的代碼,我覺得可能是一個形象在我的行動bitecodeKohana中的圖像字符串函數

我已經把頭部圖像這樣

$這個 - >請求 - > headers ['Content-Type'] ='image/jpeg';

,然後我編碼進行簡單的圖像創建

$image = imagecreate(450,250); 
$color = imagecolorallocate($image,0,0,0); 
imagestrig($image,5,34,56,"some txt",$color); 
imagejpeg($image,NULL,100); 

,我會與此路由URL這個動作 - 構造函數(控制器)/ image_creator(動作) 返回我blabla bla一個奇怪的unicode文本

沒有人知道如何實際創建圖像白衣這個框架: 我已經嘗試過這樣,但它也沒有'將不起作用: http://forum.kohanaframework.org/discussion/4412/solved-ko3-gd-and-htmlimage/p1

其實我不是想顯示它,我不需要顯示創建的圖像,我想創建圖像,然後將其發送到郵件,但我的腳本不工作,如何我可以在肌動蛋白中獲得圖像併發送郵件嗎?

+0

http://stackoverflow.com/questions/12732221/kohana-3-image-save-and-thumbnail – 2013-05-10 16:48:26

+0

http://stackoverflow.com/questions/7204059/output-image-in-a- kohana-3-2-view,也是http://stackoverflow.com/questions/5430449/kohana-3-uploading-image-without-using-any-modules – 2013-05-10 16:49:25

+0

其實我並不是試圖展示它,我不需要顯示創建的圖像,我想創建圖像,然後將其發送到郵件,但我的腳本不起作用,我怎麼能在肌動蛋白中獲得圖像並將其郵寄? – 2013-05-10 16:58:27

回答

0

最簡單的方法是保存此圖像,然後附加到電子郵件。

// ... 
$imagePath = 'tmp/'.time().uniqid().'.jpg'; 
imagejpeg($im, $imagePath); 

// Attach created image to email (let's assume you're using Swift Mailer) 
$m->attach(Swift_Attachment::fromPath($imagePath)->setDisposition('inline')); 
// ...send email  

imagedestroy($im); 
// Remove image from hard disk 
unlink($imagePath);