How to Get Image Height & Width in PHP
PHP is a versatile scripting language that can be used to create dynamic Web pages by interacting with your server files. PHP provides various methods for obtaining a broad range of information about your documents, including image file attributes. Obtain the height and width of an image using the PHP functions "getimagesize" and "list." The "getimagesize" function provides you with a variety of information about the image, including the height and width. The "list" function gives you a method to assign the values to variables you can use.
Instructions
-
-
1
Open your PHP file using a PHP, HTML or text editor.
-
2
Type the following code:
list($img_width, $img_height, $img_type, $attrs)=getimagesize("images/myimage.jpg");
The "$img_width" variable returns the width value in pixels, while "$img_height" returns the height of the image named in the "getimagesize" function.
-
-
3
Save the file and upload it to your server to test the code.
-
1
References
- Photo Credit Thinkstock Images/Comstock/Getty Images