Get Width, Height and File Type of an Image in PHP
by Hiroshi on January 14th, 2013
sponsored links
Uploading images in PHP… I store image name and size (width, height) in DB to retrieve later to use. Here is a script that will enable you to get image width and height in PHP. You can use this script in image upload forms.
<?php list($width, $height, $type, $attr) = getimagesize("image_name.jpg"); echo "Image width " .$width; echo "<BR>"; echo "Image height " .$height; echo "<BR>"; echo "Image type " .$type; echo "<BR>"; echo "Attribute " .$attr; ?> |
Result of this script:
Image width 543
Image height 200
Image type 2
Image attribute width=”543″ height=”200″
You will get the width, height, type of an image and also attribute of an image,
For Type of an image see below.
Type of Image
1 = GIF
2 = JPG
3 = PNG
4 = SWF
5 = PSD
6 = BMP
7 = TIFF (intel byte order)
8 = TIFF (motorola byte order)
9 = JPC
10 = JP2
11 = JPX
12 = JB2
13 = SWC
14 = IFF
15 = WBMP
16 = XBM
Related Posts
sponsored links
