【问题标题】:imagestring function in KohanaKohana 中的图像字符串函数
【发布时间】:2013-05-10 16:36:39
【问题描述】:

我在 Kohana 中创建图像并在其上写文本时遇到了一点问题。 如果我使用简单的 php,我的代码可以正常工作,但我无法将它集成到 Kohana 框架控制器和操作中。 当我这样做时,它会重新运行一个奇怪的代码,我认为这可能是一个图像咬代码

在我的操作中,我已经为这样的图像添加了标题

$this->request->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 执行此操作 - 构造函数(控制器)/图像创建器(操作) 它给我 blabla bla 一个奇怪的 unicode 文本

有谁知道如何使用这个框架实际创建图像: 我试过这样,但它也不起作用: http://forum.kohanaframework.org/discussion/4412/solved-ko3-gd-and-htmlimage/p1

其实我并不想显示它,我不需要显示创建的图像,我想创建图像,然后将其发送到邮件,但是我的脚本不起作用,我如何在 actin 中获取图像然后邮寄?

【问题讨论】:

标签: php kohana


【解决方案1】:

最简单的方法是保存这张图片,然后附加到电子邮件中。

// ...
$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);

【讨论】:

    猜你喜欢
    • 2013-02-18
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 2013-05-16
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 2012-07-16
    相关资源
    最近更新 更多