All PHP Tutorials
Ad Management
Counter
Email System
Forum and Guestbook
File Upload
Image Manipulation
Login / Members / Password
Pagination
Encode Script
Refresh / Redirection
Miscellaneous
All MySQL Tutorials
Create, Manage Database using phpMyAdmin
Connect to Database
Insert Data
Select Data
Edit Database
Update Database
Delete Database
Order Results
Forums



Home > PHP Tutorials
Get the width and height of an image using a function in PHP
Get the width and height of an image using a function in PHP
PHP provides a function to get the width and height of an image. The getimagesize() function will determine the size of image file including flash file(swf). 
 
  Overview

This is a very useful function in PHP, I found it on php.net
PHP provides function to get the width and height of an image. The getimagesize() function will determine the size of image file including flash file(swf).


  Syntax

list($width, $height, $type, $attr) = getimagesize("image_name.jpg");


  ############### Code

This is a sample code, change image_name to your image name and test it!

<?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;

?>


When you run this script you will see the result like this

Image width 379
Image height 344
Image type 2
Image attribute width="379" height="344"

You will get the width, height, type of an image and also attribute of an image, I use this function in my image upload form.
Type of an image you can see from table below
You can read a full manual here


  Type of the image
1 = GIF 5 = PSD 9 = JPC 13 = SWC
2 = JPG 6 = BMP 10 = JP2 14 = IFF
3 = PNG 7 = TIFF(intel byte order) 11 = JPX 15 = WBMP
4 = SWF 8 = TIFF(motorola byte order) 12 = JB2 16 = XBM
Random Tutorial
 
Alternating table row colors
Many of website use this script to alternate their table row color that selected from mysql database, very useful and cool.
 
PHP Script Image of the day
In this script shows you how to display image of the day. You can adapt this script to display quote of the day, knowledge of the day or something else you want. You don't have to change image everyday just change images once a week.
Advertisement
 
   
Hosted by Hostgator
© PHPeasystep.com 2005-2008