Page 1 of 1

MagickReadImage ERROR!

Posted: 2007-03-05T04:10:15-07:00
by aditan22
If we use MagickReadImage and somehow it cannot read the image file, it terminates the script! :shock: wow... it's a BIG problem, why does it not return FALSE value and more importantly not terminating our script?

The error is shown like below:
Fatal error: magickreadimage(): C API cannot read the file "filename.gif" (reason: Improper image header `filename.gif') [on C source line 392]

I hope there's a command that I missed here to let the script flow... please!

ps. I have searched this forum and find this thread, seems somebody got into the same problem too.

Re: MagickReadImage ERROR!

Posted: 2007-03-08T08:57:36-07:00
by squig
Hello,

I have the same Problem with MagickReadImages. When it fails to read one image the hole script is terminated without having a chance to handle this error.

According to the manual MagickReadImages should return "false" if something went wrong.

I don't think this kind of behaviour is intended, is there some way to fix this issue?
Maybe the function could net return "false" instead throw a exception?


With kind regards,

squig

Re: MagickReadImage ERROR!

Posted: 2007-03-08T20:04:07-07:00
by magick
The path forward would be to post a URL to a set of images we can download and post a script that we can run and reliably reproduce the problem you are having. If we can reproduce a problem-- we can fix it.

Re: MagickReadImage ERROR!

Posted: 2007-03-09T04:10:28-07:00
by squig
Hello,

I've tried the following code:

Code: Select all

<?php

    $wand = NewMagickWand();
    
    if(!MagickReadImages($wand, array("pic1.jpg", "pic2.jpg"))) {
        echo "error reading images.";
    }
    
    // process pics here
    MagickWriteImages($wand, "./test.jpg");

?>
It works without problems if both pics are there but ends in a "fatal error" if one or both pics aren't found.
Testing in a directory without pics should reproduce this error.

Thank you.


squig

Re: MagickReadImage ERROR!

Posted: 2007-03-09T14:20:56-07:00
by magick
The problem is simply about properly classifying an exception in MagickWand for PHP. The MagickWand author decided that not finding an image is a fatal error. It could be his intent or perhaps a misclassification of this particular exception. If we change the exception from MW_E_ERROR to MW_E_WARNING you get the results you want. We will study the issue carefully this weekend and make the classification change if it makes sense and update MagickWand for PHP 1.0.2.

Re: MagickReadImage ERROR!

Posted: 2007-03-09T17:08:44-07:00
by squig
Hello,

I would really appreciate to be able to clean up in error case and inform the user.
I'm looking forward to read your decision.


With kind regards,

squig

Re: MagickReadImage ERROR!

Posted: 2007-03-09T18:25:44-07:00
by magick
MagickWand For PHP 1.0.2 will be released tomorrow with a patch to only issue an exception and return 0 if MagickReadImages() fails to read an image. It will no longer generate a fatal error and exit the script.

Re: MagickReadImage ERROR!

Posted: 2007-03-09T21:44:31-07:00
by aditan22
Hello,

Sorry I cannot reply earlier.
I assume the patch will work also for MagickReadImage too (not MagickReadImages only)? If so, I would greatly thankful for your work in solving the problem.

Best Regards,

Re: MagickReadImage ERROR!

Posted: 2007-03-11T14:23:48-07:00
by squig
Hello,

I've tried both functions, MagickReadImage and MagickReadImages, they now return false if an image couldn't be opened.

Thank you for this improvement.


squig