<HTML ><HEAD ><TITLE >getimagesize</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Image functions" HREF="ref.image.html"><LINK REL="PREVIOUS" TITLE="gd_info" HREF="function.gd-info.html"><LINK REL="NEXT" TITLE="image_type_to_mime_type" HREF="function.image-type-to-mime-type.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.gd-info.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.image-type-to-mime-type.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.getimagesize" ></A >getimagesize</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN34174" ></A ><P > (PHP 3, PHP 4 )</P >getimagesize -- Get the size of an image</DIV ><DIV CLASS="refsect1" ><A NAME="AEN34177" ></A ><H2 >Description</H2 >array <B CLASS="methodname" >getimagesize</B > ( string filename [, array imageinfo])<BR ></BR ><P > The <B CLASS="function" >getimagesize()</B > function will determine the size of any <SPAN CLASS="acronym" >GIF</SPAN >, <SPAN CLASS="acronym" >JPG</SPAN >, <SPAN CLASS="acronym" >PNG</SPAN >, <SPAN CLASS="acronym" >SWF</SPAN >, <SPAN CLASS="acronym" >SWC</SPAN >, <SPAN CLASS="acronym" >PSD</SPAN >, <SPAN CLASS="acronym" >TIFF</SPAN >, <SPAN CLASS="acronym" >BMP</SPAN > or <SPAN CLASS="acronym" >IFF</SPAN > image file and return the dimensions along with the file type and a height/width text string to be used inside a normal <SPAN CLASS="acronym" >HTML</SPAN > <TT CLASS="literal" >IMG</TT > tag. </P ><P > Returns an array with 4 elements. Index 0 contains the width of the image in pixels. Index 1 contains the height. Index 2 is 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, 12 = JB2, 13 = SWC, 14 = IFF. These values correspond to the IMAGETYPE constants that were added in PHP 4.3. Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN34202" ></A ><P ><B >Example 1. getimagesize (file)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $size = getimagesize ("img/flag.jpg"); echo "<img src=\"img/flag.jpg\" {$size[3]}>"; ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN34206" ></A ><P ><B >Example 2. getimagesize (URL)</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $size = getimagesize ("http://www.example.com/gifs/logo.gif"); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > With <SPAN CLASS="acronym" >JPG</SPAN > images, two extra indexes are returned: <TT CLASS="literal" >channels</TT > and <TT CLASS="literal" >bits</TT >. <TT CLASS="literal" >channels</TT > will be 3 for RGB pictures and 4 for CMYK pictures. <TT CLASS="literal" >bits</TT > is the number of bits for each color. </P ><P > Beginning with PHP 4.3, <TT CLASS="literal" >bits</TT > and <TT CLASS="literal" >channels</TT > are present for other image types, too. However, the presence of these values can be a bit confusing. As an example, <SPAN CLASS="acronym" >GIF</SPAN > always uses 3 channels per pixel, but the number of bits per pixel cannot be calculated for an animated <SPAN CLASS="acronym" >GIF</SPAN > with a global color table. </P ><P > Some formats may contain no image or may contain multiple images. In these cases, <B CLASS="function" >getimagesize()</B > might not be able to properly determine the image size. <B CLASS="function" >getimagesize()</B > will return zero for width and height in these cases. </P ><P > Beginning with PHP 4.3, <B CLASS="function" >getimagesize()</B > also returns an additional parameter, <TT CLASS="literal" >mime</TT >, that corresponds with the MIME type of the image. This information can be used to deliver images with correct HTTP Content-type headers: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN34226" ></A ><P ><B >Example 3. getimagesize() and MIME types</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php $size = getimagesize ($filename); $fp=fopen($filename, "rb"); if ($size && $fp) { header("Content-type: {$size['mime']}"); fpassthru($fp); exit; } else { // error } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > If accessing the <TT CLASS="parameter" ><I >filename</I ></TT > image is impossible, or if it isn't a valid picture, <B CLASS="function" >getimagesize()</B > will return <TT CLASS="constant" ><B >FALSE</B ></TT > and generate a warning. </P ><P > The optional <TT CLASS="parameter" ><I >imageinfo</I ></TT > parameter allows you to extract some extended information from the image file. Currently, this will return the different <SPAN CLASS="acronym" >JPG</SPAN > APP markers as an associative array. Some programs use these APP markers to embed text information in images. A very common one is to embed <SPAN CLASS="acronym" >IPTC</SPAN > <A HREF="http://www.iptc.org/" TARGET="_top" >http://www.iptc.org/</A > information in the APP13 marker. You can use the <A HREF="function.iptcparse.html" ><B CLASS="function" >iptcparse()</B ></A > function to parse the binary APP13 marker into something readable. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN34239" ></A ><P ><B >Example 4. getimagesize() returning IPTC</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" ><?php $size = getimagesize ("testimg.jpg",&$info); if (isset ($info["APP13"])) { $iptc = iptcparse ($info["APP13"]); var_dump ($iptc); } ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > TIFF support was added in PHP 4.2. </P ><P > This function does not require the GD image library. </P ><P > See also <A HREF="function.image-type-to-mime-type.html" ><B CLASS="function" >image_type_to_mime_type()</B ></A >, <A HREF="function.exif-imagetype.html" ><B CLASS="function" >exif_imagetype()</B ></A >, <A HREF="function.exif-read-data.html" ><B CLASS="function" >exif_read_data()</B ></A > and <A HREF="function.exif-thumbnail.html" ><B CLASS="function" >exif_thumbnail()</B ></A >. </P ><P > URL support was added in PHP 4.0.5. </P ></BLOCKQUOTE ></DIV > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.gd-info.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.image-type-to-mime-type.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >gd_info</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.image.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >image_type_to_mime_type</TD ></TR ></TABLE ></DIV ></BODY ></HTML >