0
votes

I'm having an issue with imagick running on a MAMP installation within a cakephp app.

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). 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. The script works perfectly in a plain old php file i.e outside of cake but it hangs when visited via my cakephp app action. My action code is:

public function test(){

            $this->layout = false;
    }

Cake error log is empty.

1

1 Answers

0
votes

Okay the issue was with how the header was set in cakephp. Cake didn't allow me to set the page header in the view that way.

I added the following code to the test action:

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

And it works perfectly now.