Getimagesize PHP

11.Jul.2010

Getimagesize is a PHP function that can be useful when printing your image in HTML, as img attributes width and height are necessary if you want to have valid HTML. However, getimagesize function will not only be helpful when working with images. It will also help you determine size of uploaded flash (SWF).

This can be very useful when you want to printout uploaded SWF onto your HTML since you can now determine dimension of SWF and print out proper embed tag.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$swfFile = '/some_public_folder/getimagesize.swf';
if(file_exists($_SERVER['DOCUMENT_ROOT'] . $swfFile)) $size = getimagesize( $_SERVER['DOCUMENT_ROOT'] .  $swfFile );
else $size = array(640, 480);
 
$width = $size[0];
$height = $size[1];
 
$embed = '
<OBJECT WIDTH="' . $width . '" HEIGHT="' . $height . '" id="Getimagesize PHP SWF">
	<PARAM NAME=quality VALUE=high>
	<EMBED src="' . $swfFile . '" quality=high WIDTH="' . $width . '" HEIGHT="' . $height . '" NAME="Getimagesize PHP SWF" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</OBJECT>';
 
echo $embed;