检查图像在PHP中是否有效的最佳和最快方法是什么? [英] What is the best and fastest way to check if the image is valid in PHP?

查看:103
本文介绍了检查图像在PHP中是否有效的最佳和最快方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查图像在PHP中是否有效的最佳和最快方法是什么?
我需要能够检查GIF,JPG以及PNG图像。

What is the best and fastest way to check if the image is valid in PHP ? I need it to be able to check GIF, JPG as well as PNG images.

推荐答案

exif_imagetype 是一个更好的解决方案。

exif_imagetype is a better solution.

这种方法比使用getimagesize更快。引用 php.net 返回值是相同的值getimagesize()在索引2中返回,但exif_imagetype()要快得多。

This method is faster than using getimagesize. To quote php.net "The return value is the same value that getimagesize() returns in index 2 but exif_imagetype() is much faster."

if(exif_imagetype('path/to/image.jpg')) {
    // your image is valid
}

这篇关于检查图像在PHP中是否有效的最佳和最快方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆