Debugging phMagick

August 10, 2009 by nuno costa 15 comments

 Debugging phMagick

There are 2 ways to debug phMagick

  • Activate the debug mode, and then phMagick will issue warnings when a command fails
  • Output the execution log and you will get information on the command executed, it’s return code and any errors/output from the execution

 

If you are on Windows you might want to read this, ImageMagick and Windows both have a program named convert and that can cause problems

 

A simple debug example:

  • Create a new folder
  • Copy phMagick.php and the plugins folder to that folder
  • Copy an image to that folder and name it source.jpg
  • Create a file and name it index.php and put the following code
include 'phMagick.php';
$phMagick = new phMagick('source.jpg', 'resized.jpg');
$phMagick->debug=true;
$phMagick->resize(200,0);
echo '< img src="resized.jpg">';
echo '<pre>', print_r($phMagick->getLog()) , '</pre>';
  • Point your browser to that folder and watch the output

 

If you can’t figure it out mail me the output, I’ll do my best to help

15 comments so far Add Your Comment

  1. by Ari on September 10 2009 at 10:14

    Hi,

    I have windows environment and I can run the command on command line but the phMagick fails. The debug information is:

    phMagick: Error executing “convert -scale “200x>” -quality 80 -strip “testi.jpg” “resized.jpg”"
    return code: 1
    command output :”convert: unable to open image `resized.jpg’: Permission denied @ blob.c/OpenBlob/2480.”
    Array
    (
    [0] => Array
    (
    [cmd] => convert -scale “200x>” -quality 80 -strip “testi.jpg” “resized.jpg”
    [return] => 1
    [output] => Array
    (
    [0] => convert: unable to open image `resized.jpg’: Permission denied @ blob.c/OpenBlob/2480.
    )

    )

    )
    1

  2. by nuno costa on September 10 2009 at 13:27

    Hi Ari,

    It seems pretty obvious why you can not resize the image

    unable to open image `resized.jpg’: Permission denied

    Your web server user does not have write permission on that file or folder

  3. by Khairil Harith on October 11 2009 at 20:14

    I don’t know if its a problem or not,

    Array
    (
    [0] => Array
    (
    [cmd] => C:/progra~1/ImageMagick-6.5.6-Q16/convert -scale “200x>” -quality 80 -strip “upload_image_noword.jpg” “resized.jpg”
    [return] => 0
    [output] => Array
    (
    )

    )

    )
    1

    the image is there (within the same folder), but it didn’t resize. Any ideas?

  4. by nuno costa on October 12 2009 at 16:21

    Hello Khairil ,

    something seems to be wrong, you are getting no errors (the return code is 0 ) but the image is not created.

    have you tried to run the command from the command line ?

  5. by Jan-Berend on October 19 2009 at 12:02

    I tried to execute a command, but get this error.

    Array
    (
    [0] => Array
    (
    [cmd] => convert -density 90 -pointsize 72 label:Hello density.gif
    [return] => 4
    [output] => Array
    (
    [0] => Invalid parameter – 90
    )

    )

    )

  6. by nuno costa on October 23 2009 at 17:36
  7. by Federico on November 23 2009 at 12:45

    Please: help me. My error is:
    Array
    ( [0] => Array
    ( [cmd] => convert -scale “200x>” -quality 80 -strip “source.jpg” “resized.jpg”
    [return] => 4
    [output] => Array
    ( [0] => Parametro non valido – “200x>” )
    ))
    1

  8. by nuno costa on November 24 2009 at 12:11

    Hello Federico,

    Please check this page, http://www.francodacosta.com/blog/phmagick/examples/error-convert-invalid-parameter

    windows is using the convert.exe to convert a partition to ntfs instead of imagemagick convert.exe

  9. by Koki on March 3 2010 at 14:52

    Hi

    I need some help please. Whenever I try generating thumbnails from PDF, I get the follow error with some file and others work fine.

    Current allocation mode is local
    Last OS error: 2
    GNU Ghostscript 7.07: Unrecoverable error, exit code 1
    convert: Postscript delegate failed `extract.pdf’: No such file or directory @ pdf.c/ReadPDFImage/611.
    convert: missing an image filename `extract.png’ @ convert.c/ConvertImageCommand/2772.

    Any explanation of why this would happen.

    Thanks

  10. by nuno costa on March 9 2010 at 21:32

    I think you have a problem with your ghostscript installation

  11. by Kjetil Høiby on March 24 2010 at 12:23

    Excellent work, mr. Costa, I’ll buy you a beer later!
    At the moment I’m struggling with a function you may include freely if you so wish, but it might be a bit specialist.
    (It’s supposed to swap red and blue color channels in order to enable me to work on/upload false color IR photographs with my iPhone)

    The function I’ve written is this:

    function swapchannelsrb(){

    $cmd = $this->getBinary(‘convert’);
    $cmd .= ‘ ‘;
    $cmd .= $this->getSource();
    $cmd .= ‘ -separate’;
    $cmd .= ‘ -swap 0,2′;
    $cmd .= ‘ -combine ‘;
    $cmd .= $this->getDestination();

    $this->execute($cmd);
    $this->setSource($this->getDestination());
    $this->setHistory($this->getDestination());
    return $this ;
    }

    And I’m calling it into play with this code:

    debug=true;
    $phMagick->swapchannelsrb();

    echo ”;
    // echo ‘

    ', print_r($phMagick->getLog()) , '

    ‘;
    ?>

    The return code I’m receiving is 126.
    The example I’m using from imagemagick.org suggests this command:
    convert rose: -separate -swap 0,2 -combine rose_rb_swap.gif

    I’m submitting this command:
    convert image.jpg -separate -swap 0,2 -combine swapped.jpg

    Thanks!

  12. by Kjetil Høiby on March 25 2010 at 20:43

    Feel free to disregard my last comment, as I was confused about the installation at the time. Everything works smoothly now, it’s time for me to cough up that beer.. :)

  13. by nuno costa on March 25 2010 at 21:48

    I’m glad everything is working fine!

  14. by Prookie on August 18 2010 at 18:36

    Array
    (
    [0] => Array
    (
    [cmd] => convert -scale “200x>” -quality 80 -strip “test.png” “testDONE.jpg”
    [return] => 127
    [output] => Array
    (
    )

    )

    )

    hm, what can I do? :(

  15. by nuno costa on August 23 2010 at 19:42

    If you are using windows, 127 means command not found

More from francodacosta.com

© francodacosta.com - All rights reserved