How can we get the properties (size, type, width, height) of
an image using PHP image functions?
Answer Posted / kartihk
getimagesize ( string filename [, array imageinfo])
Returns an array with 4 elements.
Index 0 contains the width of the image in pixels.
Index 1 contains the height.
Index 2 a flag indicating the type of the 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.
Index 3 is a text string with the correct height="yyy"
width="xxx" string that can be used directly in an IMG tag.
<?php
$imgp = getimagesize ("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" {$imgp[3]}>";
?>
| Is This Answer Correct ? | 9 Yes | 2 No |
Post New Answer View All Answers
How error handling is being handled by php?
Which is faster for or foreach?
How to make database connection in php?
Can age be a variable?
> symbol is used to redirect the output of a command. State Whether True or False?
Write a program using while loop?
What is the use of $_server["php_self"] variable?
What is htmlentities function in php?
How to create reusable code in php?
What is the difference between $var and $$var?
How to get the value of current session id?
Why do we use session?
How to delete an element from an array?
What are the Formatting and Printing Strings available in PHP?
What is the difference between array_merge() and array_merge_recursive() in php?