Get image resolution in PHP
Here’s a code snippet in PHP of how to get image resolution. I mean image width and height.
There’re lots of approaches of doing that and I’ve tryed to find the short one.
1 2 |
list($width, $height, $type, $attr) = getimagesize($path_to_image); // then you may use $width and $height variables |
So, to get the image resolution you should write only one line of PHP code. Also, you can get other info about the image using the getimagesize function. $path_to_image
is a path to the image, for example, “/tmp/sunset.jpg” or “C:\Temp\image.jpg”, and in your case, it’s a path to the image the resolution of which you want to get. You can find more help about this function in PHP documentation.
To use this function the GD library is required. You don’t need any other frameworks or third party libraries.