MagickReadImage ERROR!

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
aditan22

MagickReadImage ERROR!

Post 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.
squig

Re: MagickReadImage ERROR!

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickReadImage ERROR!

Post 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.
squig

Re: MagickReadImage ERROR!

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickReadImage ERROR!

Post 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.
squig

Re: MagickReadImage ERROR!

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickReadImage ERROR!

Post 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.
aditan22

Re: MagickReadImage ERROR!

Post 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,
squig

Re: MagickReadImage ERROR!

Post 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
Post Reply