简体   繁体   English

用MAMP + PHP 5.3.6 + CakePHP的Imagick

[英]Imagick with MAMP + php 5.3.6 + cakephp

I'm having an issue with imagick running on a MAMP installation within a cakephp app. 我在cakephp应用程序中的MAMP安装上运行的imagick出现问题。

I have followed the install instructions as indicated here and the install seems to have worked in the sense that the class 'Imagick' exists for me if i test it in a php script (I can see the module is loaded in phpinfo). 我已按照此处指示的说明进行了安装,并且如果我在php脚本中对其进行测试(我可以看到该模块已加载到phpinfo中),则该安装似乎在某种程度上对我而言存在“ Imagick”类。 However any examples that I run utilising the class hang as soon as I echo any content. 但是,只要我回显任何内容,我使用该类运行的所有示例都会挂起。 My view is: 我的看法是:

<?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;
    ?>

This script will just hang as soon as the echo $canvas is encountered. 该脚本将在遇到echo $canvas立即挂起。 The script works perfectly in a plain old php file ie outside of cake but it hangs when visited via my cakephp app action. 该脚本在普通的旧php文件中(即在cake外) 可以完美运行,但通过我的cakephp应用操作访问时, 该脚本将挂起。 My action code is: 我的动作代码是:

public function test(){

            $this->layout = false;
    }

Cake error log is empty. 蛋糕错误日志为空。

Okay the issue was with how the header was set in cakephp. 好的,问题在于如何在cakephp中设置标题。 Cake didn't allow me to set the page header in the view that way. Cake不允许我以这种方式在视图中设置页面标题。

I added the following code to the test action: 我在测试操作中添加了以下代码:

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

And it works perfectly now. 现在,它可以完美运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM