Skip to content

Commit

Permalink
Use streams in ExifMetadataReader
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Jul 25, 2024
1 parent ebf9bb0 commit 8697ac2
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/Image/Metadata/ExifMetadataReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ public static function getUnsupportedReason()
if (!function_exists('exif_read_data')) {
return 'The PHP EXIF extension is required to use the ExifMetadataReader';
}
if (!in_array('data', stream_get_wrappers(), true)) {
return 'The data:// stream wrapper must be enabled';
}
if (in_array(ini_get('allow_url_fopen'), array('', '0', 0), true)) {
return 'The allow_url_fopen php.ini configuration key must be set to 1';

if (PHP_VERSION_ID < 70200) {
if (!in_array('data', stream_get_wrappers(), true)) {
return 'The data:// stream wrapper must be enabled';
}
if (in_array(ini_get('allow_url_fopen'), array('', '0', 0), true)) {
return 'The allow_url_fopen php.ini configuration key must be set to 1';
}
}

return '';
Expand Down Expand Up @@ -107,6 +110,14 @@ protected function extractFromStream($resource)
*/
private function doReadData($data)
{
if (PHP_VERSION_ID >= 70200) {
$stream = fopen('php://memory', 'r+');
fwrite($stream, $data);
rewind($stream);

return $this->extract($stream);
}

if (substr($data, 0, 2) === 'II') {
$mime = 'image/tiff';
} else {
Expand All @@ -117,9 +128,9 @@ private function doReadData($data)
}

/**
* Performs the exif data extraction given a path or data-URI representation.
* Performs the exif data extraction given a path, data-URI representation or stream.
*
* @param string $path the path to the file or the data-URI representation
* @param string|resource $path the path to the file, the data-URI representation or a stream
*
* @return array
*/
Expand Down

0 comments on commit 8697ac2

Please sign in to comment.