Example 3. getimagesize() and MIME types
<?php
$size = getimagesize($filename);
$fp=fopen($filename, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else {
// error
}
?>
If accessing the filename image is impossible, or if it
isn't a valid picture, getimagesize() will return FALSE
and generate a warning.
The optional imageinfo parameter allows you to extract
some extended information from the image file. Currently,
this will return the different JPG 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 IPTC
http://www.iptc.org/ information in the APP13 marker. You
can use the iptcparse() function to parse the binary APP13
marker into something readable. Example 4. getimagesize()
returning IPTC
<?php
$size = getimagesize("testimg.jpg", $info);
if (isset($info["APP13"])) {
$iptc = iptcparse($info["APP13"]);
var_dump($iptc);
}
?>
Note: 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, getimagesize()
returns the values for the first codestream it encounters
in the root of the file.
Note: TIFF support was added in PHP 4.2.
This function does not require the GD image library.
See also image_type_to_mime_type(), exif_imagetype(), exif_read_data()
and exif_thumbnail().
URL support was added in PHP 4.0.5.
|