mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-27 22:38:55 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@172416 c90b9560-bf6c-de11-be94-00142212c4b1
200 lines
7 KiB
XML
200 lines
7 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.25 $ -->
|
|
<!-- splitted from ./en/functions/image.xml, last change in rev 1.36 -->
|
|
<refentry id="function.getimagesize">
|
|
<refnamediv>
|
|
<refname>getimagesize</refname>
|
|
<refpurpose>Get the size of an image</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>getimagesize</methodname>
|
|
<methodparam><type>string</type><parameter>filename</parameter></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter role="reference">imageinfo</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
The <function>getimagesize</function> function will determine the
|
|
size of any <acronym>GIF</acronym>, <acronym>JPG</acronym>,
|
|
<acronym>PNG</acronym>, <acronym>SWF</acronym>,
|
|
<acronym>SWC</acronym>, <acronym>PSD</acronym>,
|
|
<acronym>TIFF</acronym>, <acronym>BMP</acronym>,
|
|
<acronym>IFF</acronym>, <acronym>JP2</acronym>,
|
|
<acronym>JPX</acronym>, <acronym>JB2</acronym>,
|
|
<acronym>JPC</acronym>, <acronym>XBM</acronym>, or
|
|
<acronym>WBMP</acronym> image file and return the dimensions along with
|
|
the file type and a height/width text string to be used inside a normal
|
|
<acronym>HTML</acronym> <literal>IMG</literal> tag.
|
|
</para>
|
|
<para>
|
|
If accessing the <parameter>filename</parameter> image is impossible,
|
|
or if it isn't a valid picture, <function>getimagesize</function>
|
|
will return &false; and generate an error of level
|
|
<varname>E_WARNING</varname>.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Support for <acronym>JPC</acronym>, <acronym>JP2</acronym>,
|
|
<acronym>JPX</acronym>, <acronym>JB2</acronym>,
|
|
<acronym>XBM</acronym>, and <acronym>WBMP</acronym> became available in
|
|
PHP 4.3.2. Support for <acronym>SWC</acronym> exists as of PHP 4.3.0
|
|
and <acronym>TIFF</acronym> support was added in PHP 4.2.0
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<simpara>
|
|
JPEG 2000 support was added in PHP 4.3.2. Note that JPC and JP2 are
|
|
capable of having components with different bit depths. In this case,
|
|
the value for "bits" is the highest bit depth encountered. Also, JP2
|
|
files may contain multiple JPEG 2000 codestreams. In this case,
|
|
<function>getimagesize</function> returns the values for the first
|
|
codestream it encounters in the root of the file.
|
|
</simpara>
|
|
</note>
|
|
<note>
|
|
<simpara>
|
|
The <function>getimagesize</function> function does not require the GD
|
|
image library.
|
|
</simpara>
|
|
</note>
|
|
<para>
|
|
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, 15 = WBMP, 16 = XBM. These values correspond to
|
|
the IMAGETYPE constants that were added in PHP 4.3.0. Index 3 is a text
|
|
string with the correct height="yyy" width="xxx" string that can be used
|
|
directly in an IMG tag.
|
|
<example>
|
|
<title>getimagesize (file)</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
|
|
echo "<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
URL support was added in PHP 4.0.5
|
|
<example>
|
|
<title>getimagesize (URL)</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$size = getimagesize("http://www.example.com/gifs/logo.gif");
|
|
|
|
// if the file name has space in it, encode it properly
|
|
$size = getimagesize("http://www.example.com/gifs/lo%20go.gif");
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
With <acronym>JPG</acronym> images, two extra indexes are returned:
|
|
<literal>channels</literal> and <literal>bits</literal>.
|
|
<literal>channels</literal> will be 3 for RGB pictures and 4 for CMYK
|
|
pictures. <literal>bits</literal> is the number of bits for each color.
|
|
</para>
|
|
<para>
|
|
Beginning with PHP 4.3.0, <literal>bits</literal> and
|
|
<literal>channels</literal> are present for other image types, too.
|
|
However, the presence of these values can be a bit confusing. As an
|
|
example, <acronym>GIF</acronym> always uses 3 channels per pixel, but the
|
|
number of bits per pixel cannot be calculated for an animated
|
|
<acronym>GIF</acronym> with a global color table.
|
|
</para>
|
|
<para>
|
|
Some formats may contain no image or may contain multiple images. In these
|
|
cases, <function>getimagesize</function> might not be able to properly
|
|
determine the image size. <function>getimagesize</function> will return
|
|
zero for width and height in these cases.
|
|
</para>
|
|
<para>
|
|
Beginning with PHP 4.3.0, <function>getimagesize</function> also returns an
|
|
additional parameter, <literal>mime</literal>, that corresponds with the
|
|
MIME type of the image. This information can be used to deliver images
|
|
with correct HTTP Content-type headers:
|
|
<example>
|
|
<title>getimagesize() and MIME types</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$size = getimagesize($filename);
|
|
$fp=fopen($filename, "rb");
|
|
if ($size && $fp) {
|
|
header("Content-type: {$size['mime']}");
|
|
fpassthru($fp);
|
|
exit;
|
|
} else {
|
|
// error
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
The optional <parameter>imageinfo</parameter> parameter allows
|
|
you to extract some extended information from the image
|
|
file. Currently, this will return the different
|
|
<acronym>JPG</acronym> 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 <acronym>IPTC</acronym>
|
|
<ulink url="&url.iptc;">&url.iptc;</ulink> information in the
|
|
APP13 marker. You can use the <function>iptcparse</function>
|
|
function to parse the binary APP13 marker into something
|
|
readable.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>getimagesize() returning IPTC</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$size = getimagesize("testimg.jpg", $info);
|
|
if (isset($info["APP13"])) {
|
|
$iptc = iptcparse($info["APP13"]);
|
|
var_dump($iptc);
|
|
}
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
See also <function>image_type_to_mime_type</function>,
|
|
<function>exif_imagetype</function>,
|
|
<function>exif_read_data</function> and
|
|
<function>exif_thumbnail</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|
|
|