Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP PHP Get Image Width And Height

PHP Get Image Width And Height

There is a PHP function: GetImageSize that returns the actual dimensions (width & height) as well as the type (GIF, PNG, JPG, SWF, PSD, BMP, etc) of a particular image.

The function is useful when you want to resize or generate thumbnail of an image, you may need to determine its width and height. It’s also useful when you want to display a dynamic image (be downloaded from an external resource or uploaded by user) on the HTML page.

PHP Get Image Width And Height – Example

<?php
	$image_name = "Desert.jpg";
 
	list($width, $height, $type, $sizes) = GetImageSize($image_name);
 
	echo "width: " . $width . "<br>";
	echo "height: " . $height . "<br>";
	echo "type: " . $type . "<br>";
	echo "sizes: " . $sizes . "<br>";
?>

<?php $image_name = "Desert.jpg"; list($width, $height, $type, $sizes) = GetImageSize($image_name); echo "width: " . $width . "<br>"; echo "height: " . $height . "<br>"; echo "type: " . $type . "<br>"; echo "sizes: " . $sizes . "<br>"; ?>

Note: flag for image type:

1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(orden de bytes intel), 8 = TIFF(orden de bytes motorola), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM.

Output of the example:

width: 1024
height: 768
type: 2
sizes: width="1024" height="768"

width: 1024 height: 768 type: 2 sizes: width="1024" height="768"

Display Dynamic Image With Width And Height

<?php
	echo "<img src=\"" . $image_name . "\" " . $sizes . " alt=\"Get Image Width And Height Example\" />";
?>

<?php echo "<img src=\"" . $image_name . "\" " . $sizes . " alt=\"Get Image Width And Height Example\" />"; ?>

Download the PHP script above, it includes the jpg image (Desert.jpg) for your testing.

Sep 4, 2011Hoan Huynh
How To Reduce Delay Time Checking New Emails In ThunderbirdHow To Delete Application In Facebook Developers
You Might Also Like:
  • Get Image Width Height With JQuery And JavaScript
  • PHP Get Remote Image Width Height
  • Facebook Like Button And Recommend Button With fb:like, iframe and html5
  • How To Track Website With Multiple Google Analytisc Accounts
  • C# Save Web Page URL To Image
  • Jquery checkbox checked
  • Google Map Supported Type And Simple Example
  • ASP.NET Resize Image High Quality
  • Share Page On Facebook With Thumbnail Featured Image
  • Javascript Problem Set focus textbox on Firefox
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

10 years ago PHPGetImageSize322
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
24,469 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
21,844 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
17,661 views
JQuery Allow only numeric characters or only alphabet characters in textbox
15,004 views
C# Read Json From URL And Parse/Deserialize Json
11,737 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Things to Learn about Installingderm Loan Type S
  • Online Photo Editor – Free Photoediting Software
  • A Guide to Finding the Best Paper Sellers
  • Photoediting in Home Isn’t Hard to Do!

  • Free Photo Editor Online
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (27)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (647)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development