getimagesize
getimagesize
Get the size of an image
**getimagesize** string $filename array $image_info
The function will determine the
size of any supported given image file and return the dimensions along with
the file type and a text string to be used inside a
normal tag and the
correspondent content type.
getimagesize``height/width
can also return some more information
in parameter.
getimagesize``image_info
Let op: > This function expects to be a valid image file. If a non-image file is supplied, it may be incorrectly detected as an image and the function will return successfully, but the array may contain nonsensical values.
filenameDo not use to check that a given file is a valid image. Use a purpose-built solution such as the extension instead.
getimagesizeFileinfo
Opmerking: > 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 . In this case, returns the values for the first codestream it encounters in the root of the file.
multiple JPEG 2000 codestreams``getimagesize
Opmerking: > The information about icons are retrieved from the icon with the highest bitrate.
Opmerking: > GIF images consist of one or more frames, where each frame may only occupy part of the image. The size of the image which is reported by is the overall size (read from the logical screen descriptor).
getimagesize
filename
This parameter specifies the file you wish to retrieve information
about. It can reference a local file or (configuration permitting) a
remote file using one of the .
supported streams
image_info
This optional parameter allows you to extract some extended
information from the image file. Currently, this will return the
different 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
information in the APP13 marker.
You can use the function to parse the
binary APP13 marker into something readable.
IPTCiptcparse
Opmerking: > The only supports files.
image_info
Returns an array with up to 7 elements. Not all image types will include
the and elements.
channels``bits
Index 0 and 1 contains respectively the width and the height of the image.
Opmerking: > Some formats may contain no image or may contain multiple images. In these cases, might not be able to properly determine the image size. will return zero for width and height in these cases.
getimagesize``getimagesize
Opmerking: > is agnostic of any image metadata. If e.g. the Exif flag is set to a value which rotates the image by 90 or 270 degress, index 0 and 1 are swapped, i.e. the contain the height and width, respectively.
getimagesize``Orientation
Index 2 is one of the constants indicating
the type of the image.
IMAGETYPE_*
Index 3 is a text string with the correct
string that can be used
directly in an tag.
height="yyy" width="xxx"
is the correspondant MIME type of the image.
This information can be used to deliver images with the correct HTTP header:
mime``Content-typeVoorbeeld: and MIME types
<?php
$size = getimagesize($filename);
$fp = fopen($filename, "rb");
if ($size && $fp) {
header("Content-type: {$size['mime']}");
fpassthru($fp);
exit;
} else {
// error
}
?>
will be 3 for RGB pictures and 4 for CMYK
pictures.
channels
is the number of bits for each color.
bits
For some image types, the presence of and
values can be a bit
confusing. As an example, always uses 3 channels
per pixel, but the number of bits per pixel cannot be calculated for an
animated with a global color table.
channels``bits
On failure, false is returned.
If accessing the image is impossible
will generate an error of level
. On read error,
will generate an error of level
.
filename``getimagesize``E_WARNING``getimagesize``E_NOTICE
As of PHP 8.0.0, a is thrown
if is empty.
filename
Voorbeeld: example
<?php
list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
echo "<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />";
?>
Voorbeeld: getimagesize (URL)
<?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");
?>
Voorbeeld: getimagesize() returning IPTC
<?php
$size = getimagesize("testimg.jpg", $info);
if (isset($info["APP13"])) {
$iptc = iptcparse($info["APP13"]);
var_dump($iptc);
}
?>
image_type_to_mime_type``exif_imagetype``exif_read_data``exif_thumbnail``imagesx``imagesy