★ wanayoo — archive 1999 http://www.php.net/manual/it/function.getimagesize.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Graphics
Quick Reference
English version of this pageGerman version of this pageJapanese version of this pageFrench version of this pageHungarian version of this page
Graphics
* GetImageSize
* ImageArc
* ImageChar
* ImageCharUp
* ImageColorAllocate
* ImageColorDeAllocate
* ImageColorAt
* ImageColorClosest
* ImageColorExact
* ImageColorResolve
* ImageGammaCorrect
* ImageColorSet
* ImageColorsForIndex
* ImageColorsTotal
* ImageColorTransparent
* ImageCopy
* ImageCopyResized
* ImageCreate
* ImageCreateFromGif
* ImageCreateFromJPEG
* ImageCreateFromPNG
* ImageDashedLine
* ImageDestroy
* ImageFill
* ImageFilledPolygon
* ImageFilledRectangle
* ImageFillToBorder
* ImageFontHeight
* ImageFontWidth
* ImageGIF
* ImagePng
* ImageJPEG
* ImageInterlace
* ImageLine
* ImageLoadFont
* ImagePolygon
* ImagePSBBox
* ImagePSEncodeFont
* ImagePSFreeFont
* ImagePSLoadFont
* ImagePsExtendFont
* ImagePsSlantFont
* ImagePSText
* ImageRectangle
* ImageSetPixel
* ImageString
* ImageStringUp
* ImageSX
* ImageSY
* ImageTTFBBox
* ImageTTFText
Manual: GetImageSize
View the source code for this pageSearch the site



Previous page
 Graphics
 Updated
Sun, 06 Aug 2000
ImageArc 
Next page


GetImageSize

(unknown)

GetImageSize -- Get the size of a GIF, JPEG, PNG or SWF image

Description

array getimagesize (string filename [, array imageinfo])

The GetImageSize() function will determine the size of any GIF, JPG, PNG or SWF image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag.

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. Index 3 is a text string with the correct "height=xxx width=xxx" string that can be used directly in an IMG tag.

Esempio 1. GetImageSize


<?php $size = GetImageSize ("img/flag.jpg"); ?>
<IMG SRC="/old?u=http%3A%2F%2Fwww.php.net%2Fmanual%2Fit%2Fimg%2Fflag.jpg&y=1999" <?php echo $size[3]; ?>
      

The optional imageinfo parameter allows you to extract some extended information from the image file. Currently this will return the diffrent JPG APP markers in an associative Array. Some Programs use these APP markers to embedd text information in images. A very common one in to embed IPTC http://www.xe.net/iptc/ information in the APP13 marker. You can use the iptcparse() function to parse the binary APP13 marker into something readable.

Esempio 2. GetImageSize returning IPTC


<?php 
    $size = GetImageSize ("testimg.jpg",&$info);
    if (isset ($info["APP13"])) {
        $iptc = iptcparse ($info["APP13"]);
        var_dump ($iptc);
    }
?>
      

Nota: This function does not require the GD image library.


User Contributed Notes: GetImageSize


stevet@linuxfan.com
18-Apr-1999 10:18
The filename needs to be either relative to the current document, or an absolute filesystem path. Thus absolute URL paths will not work.

To use absolute URL paths, use $DOCUMENT_ROOT . $imagepath



mikeb@map.com
05-Aug-1999 04:17
Is there any way to get this function to get the size of a remotely hosted image without having to write a program to download, get the size then remove it?


paul@frogtree.com
11-Aug-1999 08:19
I'm wondering the same thing as Mike. Has anyone found a way to find the size of an image that's remotely hosted? (without storing a temporary file)


thomas@vcsites.com
04-Oct-1999 01:21
To get the file size use the filesize(string filename) command

see: http://www.php.net/manual/function.filesize.php3



agent86@iname.com
19-Oct-1999 08:35
similarly, Is there any way to get the size of an image file in a database?


bolke@xs4all.nl
02-Dec-1999 04:48
the GD libary uses a pointer to the image, so through GD it should be possible
to get a size of an image stored in a database.
But how to do this with PHP? How to get a pointer to the binary data?



spot@razorshift.com
07-Dec-1999 10:08
If you have the luxary of being the controlling application that added the image to the database, you can check the filesize before writing it and store that in a seprate field.


everton@dextra.com.br
13-Dec-1999 08:34
The sample code didn't worked for me.
The following one did:

<pre>
if (isset($info["APP13"])) {
$iptc = iptcparse($info["APP13"]);

if (is_array($iptc)) {
while(list($key, $val) = each($iptc)) {
while(list($k, $v) = each($val)) {
echo "$k => \"$v\"
\n";
}
}
}
}
</pre>



webmaster@feartheclown.com
29-Dec-1999 05:44
I found I was able to get the dimensions of an image just prior to storing it in the database. I did this by using GetImageSize on the actual data, not the filename. This allowed me to get the dimensions without having to create a tmp file.

<PRE>
$imagehw = GetImageSize($form_data);

// Do this prior to adding slashes
// to the data.

$imagehw[0] = $imagewidth;
$imagehw[1] = $imageheight;

// Proceed with storing the image.
</PRE>



metutu@max.drigon.com
12-Jan-2000 04:18
Is it possible to get the number of colors or the bpp for an image ?


tchr@elq.org
01-Feb-2000 07:04

We noticed several request for a way to get the image info without having to download and/or write the data to a file ifit is either remote orin a base.

Gosub of ELQ has written a 150 lines php3 script that does this for you, and unlike php own, rather stupid way to do it you'll send the data as a string to the function, and it will return an array much like phps own getImageSize.

The scipt is available at

<pre>ftp://ftp.elq.org/pub/php3/elqGetImageFormat/</pre>

tChr/ELQ




thecaptain@softhome.net
04-Apr-2000 04:50
I used this code it it did not work for me...could someone proofread it??*$image_size = getimagesize("img/$logo");

if ($image_size[0] > 100)
{
$width = 100;
$height = (100 * $image_size[1])/$image_size[0];
}
else
{
$width = $image_size[0];
$height = $image_size[1];
}


exec("cp $logo /home/online/www/images/$logo_name");

and in a table: print "<img src=/old?u=http%3A%2F%2Fwww.php.net%2Fmanual%2Fit%2F%5C%26quot%3Bhttp%3A%2Fwww.cfsquad.com%2Fimages%2F%24logo%5C%26quot&y=1999 width=$width height=$height border='0'></td>";

It stores the image but gives me and error: Warning: Unable to open img/none in /home/online/www/php/addsquad.php3 on line 86

line 86 is the maked with a * symbol

Thanks,
Ryan




thecaptain@softhome.net
04-Apr-2000 04:52
I used this code it it did not work for me...could someone proofread it??
<pre>
*$image_size = getimagesize("img/$logo");

if ($image_size[0] > 100)
{
$width = 100;
$height = (100 * $image_size[1])/$image_size[0];
}
else
{
$width = $image_size[0];
$height = $image_size[1];
}


exec("cp $logo /home/online/www/images/$logo_name");

and in a table: print "<img src=/old?u=http%3A%2F%2Fwww.php.net%2Fmanual%2Fit%2F%5C%26quot%3Bhttp%3A%2Fwww.cfsquad.com%2Fimages%2F%24logo%5C%26quot&y=1999 width=$width height=$height border='0'></td>";

It stores the image but gives me and error: Warning: Unable to open img/none in /home/online/www/php/addsquad.php3 on line 86</pre>

line 86 is the maked with a * symbol

Thanks,
Ryan




 About Notes


Previous page
 Graphics
 Updated
Sun, 06 Aug 2000
ImageArc 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.