exif_read_data
Description
The exif_read_data of Exif for PHP reads the EXIF headers from an image file.
Syntax
exif_read_data( resource|string $file, ?string $required_sections = null, bool $as_arrays = false, bool $read_thumbnail = false ): array|false
Parameters
file
The location of the image file. This can either be a path to the file (stream wrappers are also supported as usual) or a stream resource.
required_sections
A comma separated list of sections that need to be present in file to produce a result array. If none of the requested sections could be found the return value is false.
Section | Description |
---|---|
FILE | FileName, FileSize, FileDateTime, SectionsFound |
COMPUTED | html, Width, Height, IsColor, and more if available. Height and Width are computed the same way getimagesize() does so their values must not be part of any header returned. Also, html is a height/width text string to be used inside normal HTML. |
ANY_TAG | Any information that has a Tag e.g. IFD0, EXIF, ... |
IFD0 | All tagged data of IFD0. In normal imagefiles this contains image size and so forth. |
THUMBNAIL | A file is supposed to contain a thumbnail if it has a second IFD. All tagged information about the embedded thumbnail is stored in this section. |
COMMENT | Comment headers of JPEG images. |
EXIF | The EXIF section is a sub section of IFD0. It contains more detailed information about an image. Most of these entries are digital camera related. |
as_arrays
Specifies whether or not each section becomes an array. The required_sections COMPUTED, THUMBNAIL, and COMMENT always become arrays as they may contain values whose names conflict with other sections.
read_thumbnail
When set to true the thumbnail itself is read. Otherwise, only the tagged data is read.
Return
Returns an associative array where the array indexes are the header names and the array values are the values associated with those headers. Returns false if no data can be returned.
Examples
1 · file
<? $file = $_SERVER["DOCUMENT_ROOT"] . "/assets/jpg/1.jpg"; $return = exif_read_data($file); print_r($return);
Array ( [FileName] => 1.jpg [FileDateTime] => 1745202351 [FileSize] => 887 [FileType] => 2 [MimeType] => image/jpeg [SectionsFound] => COMMENT [COMPUTED] => Array ( [html] => width="100" height="100" [Height] => 100 [Width] => 100 [IsColor] => 1 ) [COMMENT] => Array ( [0] => CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ) )
2 · required_sections
<? $file = $_SERVER["DOCUMENT_ROOT"] . "/assets/jpg/1.jpg"; $required_sections = "COMPUTED"; $return = exif_read_data($file, $required_sections); print_r($return);
Array ( [FileName] => 1.jpg [FileDateTime] => 1745202351 [FileSize] => 887 [FileType] => 2 [MimeType] => image/jpeg [SectionsFound] => COMMENT [COMPUTED] => Array ( [html] => width="100" height="100" [Height] => 100 [Width] => 100 [IsColor] => 1 ) [COMMENT] => Array ( [0] => CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ) )
3 · as_arrays
<? $file = $_SERVER["DOCUMENT_ROOT"] . "/assets/jpg/1.jpg"; $required_sections = "COMPUTED"; $as_arrays = true; $return = exif_read_data($file, $required_sections, $as_arrays); print_r($return);
Array ( [FILE] => Array ( [FileName] => 1.jpg [FileDateTime] => 1745202351 [FileSize] => 887 [FileType] => 2 [MimeType] => image/jpeg [SectionsFound] => COMMENT ) [COMPUTED] => Array ( [html] => width="100" height="100" [Height] => 100 [Width] => 100 [IsColor] => 1 ) [COMMENT] => Array ( [0] => CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ) )
4 · read_thumbnail
<? $file = $_SERVER["DOCUMENT_ROOT"] . "/assets/jpg/1.jpg"; $required_sections = "COMPUTED"; $as_arrays = true; $read_thumbnail = true; $return = exif_read_data($file, $required_sections, $as_arrays, $read_thumbnail); print_r($return);
Array ( [FILE] => Array ( [FileName] => 1.jpg [FileDateTime] => 1745202351 [FileSize] => 887 [FileType] => 2 [MimeType] => image/jpeg [SectionsFound] => COMMENT ) [COMPUTED] => Array ( [html] => width="100" height="100" [Height] => 100 [Width] => 100 [IsColor] => 1 ) [COMMENT] => Array ( [0] => CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ) )
5 · index
<? $file = $_SERVER["DOCUMENT_ROOT"] . "/assets/jpg/1.jpg"; $required_sections = "COMPUTED"; $return = exif_read_data($file, $required_sections); foreach($return["COMPUTED"] as $key => $value) { echo "$key: $value\n"; }
html: width="100" height="100" Height: 100 Width: 100 IsColor: 1