PHP | exif_read_data() Function
Last Updated :
19 Feb, 2020
The exif_read_data() function is an inbuilt function in PHP which is used to read the EXIF headers from an image file.
Syntax:
array exif_read_data( mixed $stream, string $sections,
bool $arrays, bool $thumbnail )
Parameters: This function accepts four parameters as mentioned above and described below:
- $stream: It specifies the image file.
- $sections (Optional): It specifies the comma separated list of sections.
- $arrays (Optional): It specifies whether not to present each section as array.
- $thumbnail (Optional): It specifies whether to read thumbnail or not.
Return Value: This function returns an associative array on success or FALSE on failure.
Below examples illustrate the exif_read_data() function in PHP:
Example 1:
<?php
$fp = fopen ( './geeksforgeeks.jpg' , 'rb' );
$headers = exif_read_data( $fp );
echo 'EXIF Headers:' . '<br>' ;
print ( "<pre>" .print_r( $headers , true). "</pre>" );
?>
|
Output:
EXIF Headers:
Array
(
[FileName] => geeksforgeeks.jpg
[FileDateTime] => 1580889002
[FileSize] => 17763
[FileType] => 2
[MimeType] => image/jpeg
[SectionsFound] =>
[COMPUTED] => Array
(
=> width="667" height="184"
[Height] => 184
[Width] => 667
[IsColor] => 1
)
)
Example 2:
<?php
$image = new Imagick(
$image ->commentImage( "GeeksforGeeks" );
$image ->writeImage( 'geeksforgeeks.jpg' );
$fp = fopen ( './geeksforgeeks.jpg' , 'rb' );
$headers = exif_read_data( $fp , 'COMMENT' , true, true);
echo 'EXIF Headers:' . '<br>' ;
print ( "<pre>" .print_r( $headers [ 'COMMENT' ], true). "</pre>" );
?>
|
Output:
EXIF Headers:
Array
(
[0] => GeeksforGeeks
)
Reference: https://www.php.net/manual/en/function.exif-read-data.php
Share your thoughts in the comments
Please Login to comment...