2013-05-10 40 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);