PHP: cannot catch errors.

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
sparkdaemon
Posts: 4
Joined: 2014-12-23T08:51:21-07:00
Authentication code: 6789

PHP: cannot catch errors.

Post by sparkdaemon »

First, I'm French, i will try to speak English best as i can.

I'm running a server on Debian (Debian GNU/Linux 7) with php (5.4.35-0+deb7u2) and Apache.

I'm creating an API with Laravel, and i have a problem when i upload a file that Imagick can't use.

Code: Select all

static function createThumbWithHash($filePath, $fileHash) {
                try
                {
                     $im = new \imagick();
                     $im->setResourceLimit(\imagick::RESOURCETYPE_MEMORY, 1024);
                     $im->setResourceLimit(\imagick::RESOURCETYPE_MAP, 256);
                     $im->setResourceLimit(\imagick::RESOURCETYPE_AREA, 1512);
                     $im->setResourceLimit(\imagick::RESOURCETYPE_FILE, 768);
                     $im->setResourceLimit(\imagick::RESOURCETYPE_DISK, -1);
                 
                     $tmpFile = tempnam(sys_get_temp_dir(), "thumb_");
                     $im->readImage($filePath);
                     $im->setImageFormat('jpg');
                     //Scale the image
                     $im->thumbnailImage(200, 200, true);
                     //Write the new image to a file
                     $im->writeImage($tmpFile);

                 } catch (ErrorDelegate $e) {

                         Log::info("getThumbHash: ".$e->getMessage());
                         return Response::json(array("error" => "Not image", "id" => "4", "desc" => "not image"), 418);
                 }
                 catch (Exception $e){
                         Log::info("getThumbHash: Unknown Error: " . $e->getMessage());
                         return Response::json(array("error" => "Unknown", "id" => "5", "desc" => "Unknown", "ErrorLevel" => "Error"), 418);
                 }
                 if (!self::moveFileToHash($tmpFile, $fileHash, "thumbnail"))
                         return false;
                 return true;
         } 
the exception occurs at:

Code: Select all

$im->readImage($filePath);
When i upload a file that imagick can't use, Imagick throw an exception, but my code don't catch it and the server return code 500, But Laravel catch the error, i don't understand why. (I searched for many solutions on the web)

Can you help me guys?

thanks ♥
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: PHP: cannot catch errors.

Post by Bonzo »

Search this page for error and it might help you out: http://www.phpro.org/tutorials/Imagick.html
sparkdaemon
Posts: 4
Joined: 2014-12-23T08:51:21-07:00
Authentication code: 6789

Re: PHP: cannot catch errors.

Post by sparkdaemon »

I already seen this page, and it doesn't help me :s
sparkdaemon
Posts: 4
Joined: 2014-12-23T08:51:21-07:00
Authentication code: 6789

Re: PHP: cannot catch errors.

Post by sparkdaemon »

Up ^^' I still need help please :)
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: PHP: cannot catch errors.

Post by Bonzo »

I would try posting on a forum like sitepoint in the php section as you may find a way to catch the error.
sparkdaemon
Posts: 4
Joined: 2014-12-23T08:51:21-07:00
Authentication code: 6789

Re: PHP: cannot catch errors.

Post by sparkdaemon »

sitepoint? i don't know this site, i go see, thanks
Post Reply