我想省略解析所提到的函数的错误消息字符串,以获得错误的确切含义。下面是原因的解释。
我创建了以下函数,用于检查图像是否有效、JPEG或PNG是否有效并检查其完整性:
function validateImageByCreatingImageResource($filePath)
{
$validationResult = true;
$exif = exif_imagetype($filePath);
if ($exif === false) {
$validationResult = false;
}
if ($exif) {
$imageResource = false;
switch ($exif) {
case IMAGETYPE_JPEG:
case IMAGETYPE_JPEG2000:
$imageResource = @imagecreatefromjpeg($filePath);
break;
case IMAGETYPE_PNG:
$imageResource = @imagecreatefrompng($filePath);
break;
}
if ($imageResource !== false) {
imagedestroy($imageResource);
}
}
$error = error_get_last();
if (is_array($error)) {
error_clear_last();
$validationResult = false;
}
return $validationResult;
}现在,我可以检测错误,但问题在于它们的处理。例如,下面是两个类型为E_NOTICE的错误
我的问题是:我当然可以解析错误消息字符串,但是是否有更好的方法单独处理这些错误?
另外,我没有找到任何其他解决方案(通过使用php工具)来验证图像完整性。
===================================EDIT====================================
为了澄清更多问题:我需要确定图像到底有什么问题,因为我需要处理图像部分上传到服务器并允许有效的图像,但在图像标记结束后的文件末尾有附加信息的情况。
array getimagesize ( string $filename [, array &$imageinfo ] )为数组提供以下信息:
[
0 => integer width
1 => integer height
2 => integer type
3 => string 'width="<width>" height="<height>"'
bits => from what i understand it is color bits
channels => integer number of channels
mime => mime type eg. 'image/jpeg'
]只有当图像元数据无效时,它才会发出警告。没有关于正确的SOS标记(如E_WARNING )的信息来自imagecreatefromjpeg()
发布于 2018-06-21 15:47:36
这个怎么样:
array getimagesize ( string $filename [, array &$imageinfo ] )返回包含图像信息的数组,如果图像无效,则返回FALSE。
http://php.net/manual/en/function.getimagesize.php
https://stackoverflow.com/questions/50968885
复制相似问题