Search code examples
phpimage-processinggddimensionsgetimagesize

Php: get image dimensions from file or resource


I wand to get the dimensions of image files on my server using php. I am using both imagesx getimagesize in my code and I am wondering if I should use one of the other...

Does getimagesize pull info from the file meta data, or does it count pixels?

If getimagesize counts pixels... Is there another way to attempt to get dimensions from an image file's meta data? Would calling both imagesx and imagesy be more effective that calling getimagesize if the image resource is already open?

Thanks


Solution

  • getimagesize gets the sizes from the first bytes of the file (https://www.php.net/manual/en/function.getimagesize.php)

    I don't know the performance differences between the two options (EXIF-data or counting pixels). But you can easily test this.