What is the best and fastest way to check if the image is valid in PHP?

前端 未结 6 1333
别那么骄傲
别那么骄傲 2021-01-01 11:07

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.

6条回答
  •  温柔的废话
    2021-01-01 11:38

    exif_imagetype is much faster than getimagesize and doesn't use gd-Lib (leaving a leaner mem footprint)

    function isImage($pathToFile)
    {
      if( false === exif_imagetype($pathToFile) )
       return FALSE;
    
       return TRUE;
    }
    

提交回复
热议问题