【问题标题】:Imagick with MAMP + php 5.3.6 + cakephpImagick 与 MAMP + php 5.3.6 + cakephp
【发布时间】:2013-04-03 02:09:15
【问题描述】:

我在 cakephp 应用程序中的 MAMP 安装上运行 imagick 时遇到问题。

我已按照here 指示的安装说明进行操作,如果我在 php 脚本中对其进行测试,安装似乎对我来说存在“Imagick”类(我可以看到模块已加载) php 信息)。但是,只要我回显任何内容,我使用该类运行的任何示例都会挂起。我的看法是:

<?php
    /* Create a new imagick object */
    $im = new Imagick();

    /* Create new image. This will be used as fill pattern */
    $im->newPseudoImage(50, 50, "gradient:red-black");

    /* Create imagickdraw object */
    $draw = new ImagickDraw();

    /* Start a new pattern called "gradient" */
    $draw->pushPattern('gradient', 0, 0, 50, 50);

    /* Composite the gradient on the pattern */
    $draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im);

    /* Close the pattern */
    $draw->popPattern();

    /* Use the pattern called "gradient" as the fill */
    $draw->setFillPatternURL('#gradient');

    /* Set font size to 52 */
    $draw->setFontSize(52);

    /* Annotate some text */
    $draw->annotation(20, 50, "Hello World!");

    /* Create a new canvas object and a white image */
    $canvas = new Imagick();
    $canvas->newImage(350, 70, "white");

    /* Draw the ImagickDraw on to the canvas */
    $canvas->drawImage($draw);

    /* 1px black border around the image */
    $canvas->borderImage('black', 1, 1);

    /* Set the format to PNG */
    $canvas->setImageFormat('png');

    /* Output the image */
    header("Content-Type: image/png");
    echo $canvas;
    ?>

只要遇到echo $canvas,这个脚本就会挂起。 该脚本在一个普通的旧 php 文件中完美运行,即在 cake 之外,但通过我的 cakephp 应用程序操作访问时它会挂起。我的操作代码是:

public function test(){

            $this->layout = false;
    }

Cake 错误日志为空。

【问题讨论】:

    标签: php apache cakephp mamp imagick


    【解决方案1】:

    好的,问题在于如何在 cakephp 中设置标头。 Cake 不允许我以这种方式在视图中设置页眉。

    我在测试动作中添加了以下代码:

    $this->response->type("image/png");
    

    现在可以完美运行了。

    【讨论】:

      猜你喜欢
      • 2013-06-16
      • 1970-01-01
      • 2011-09-13
      • 2015-04-06
      • 2014-07-12
      • 1970-01-01
      • 2010-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多