本文介绍了如何知道imagick是否抛出错误-PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用imagick在我的网站上进行图像处理.我已正确安装它,并且运行良好.这是我的起始代码-:

I am currently using imagick for image processing on my webssite. I have it correctly installed and is working great. Heres my starting code -:

$image = new imagick($filename); $geo=$image->getImageGeometry();
$image->setImageInterlaceScheme(2);  $image->setImageCompressionQuality(85);
$image->setImageBackgroundColor('white'); $image = $image->flattenImages();
$image->setImageFormat('jpg');   $image->stripImage();

在此之后,我将完成其余部分.现在假设它抛出一个错误,我该如何编码.我尝试在$image = new imagick($filename)之后添加if(!$image){ echo 'error' exit(); },但没有成功.

After this i do the rest of the part. Now suppose it throws an error, how do i code for that. I tried adding if(!$image){ echo 'error' exit(); } after $image = new imagick($filename) but in vain.

请帮助...谢谢大家:)

Please help... Thanks all :)

推荐答案

如果发生错误,Imagick将抛出一个ImagickException,您可以捕获该错误:

If an error occurs, Imagick will throw an ImagickException which you can catch:

    try {
        $image = new Imagick($filename);
        $geo = $image->getImageGeometry();
        $image->setImageInterlaceScheme(2);
        $image->setImageCompressionQuality(85);
        $image->setImageBackgroundColor('white');
        $image = $image->flattenImages();
        $image->setImageFormat('jpg');
        $image->stripImage();
    } catch (ImagickException $e)
{
        var_dump($e);
    }

有关更多参考,请参见此处.

for further reference see here.

这篇关于如何知道imagick是否抛出错误-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 23:17