
Can getimagesize be used to validate image files? ico files may also fail as PHP only added support for icon files version 5.3. As a result, the getimagesize function will return a boolean FALSE value if you are using an earlier version than that. Support for Google’s WebP format was not added until PHP version 7.1. In my case, PHP printed out “272 X 92” onto the page. Taking the above information into account, you can print out the dimensions of the image like so: //Printing out width X height.Įcho $sizeInfo.

The integer in question corresponds to one of the IMAGETYPE_* constants.

#Php get image imagetype full#
If it is in a different location, you will need to specify the full or relative path. In this case, the code assumes that the file is in the same directory as our PHP script. We specified the path to our image file.var_dump the array that getimagesize returned. Throw new Exception('Could not get image size of: '.

Throw an exception if the function failed. Use getimagesize to get size info about the image. Let’s look at a simple example: //The path and filename of our image. Thankfully, PHP has a handy built-in function called getimagesize, which will do most of the tough work for us.
#Php get image imagetype how to#
In this tutorial, I will be showing you how to get the width and height of an image using PHP.
