Skip to content

Commit

Permalink
Merge pull request #321 from StudioMaX/issue-320
Browse files Browse the repository at this point in the history
count($jpeg_header_data) may cause an error since PHP7.2
  • Loading branch information
JamesHeinrich authored May 15, 2021
2 parents 6e2e30f + 592a038 commit 510a46d
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions getid3/module.tag.xmp.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function getAllTags()
* Reads all the JPEG header segments from an JPEG image file into an array
*
* @param string $filename - the filename of the JPEG file to read
* @return array|boolean $headerdata - Array of JPEG header segments,
* @return array|false $headerdata - Array of JPEG header segments,
* FALSE - if headers could not be read
*/
public function _get_jpeg_header_data($filename)
Expand Down Expand Up @@ -192,31 +192,34 @@ public function _get_jpeg_header_data($filename)
* Retrieves XMP information from an APP1 JPEG segment and returns the raw XML text as a string.
*
* @param string $filename - the filename of the JPEG file to read
* @return string|boolean $xmp_data - the string of raw XML text,
* FALSE - if an APP 1 XMP segment could not be found, or if an error occured
* @return string|false $xmp_data - the string of raw XML text,
* FALSE - if an APP 1 XMP segment could not be found, or if an error occurred
*/
public function _get_XMP_text($filename)
{
//Get JPEG header data
$jpeg_header_data = $this->_get_jpeg_header_data($filename);

//Cycle through the header segments
for ($i = 0; $i < count($jpeg_header_data); $i++)
{
// If we find an APP1 header,
if (strcmp($jpeg_header_data[$i]['SegName'], 'APP1') == 0)
{
// And if it has the Adobe XMP/RDF label (http://ns.adobe.com/xap/1.0/\x00) ,
if (strncmp($jpeg_header_data[$i]['SegData'], 'http://ns.adobe.com/xap/1.0/'."\x00", 29) == 0)
{
// Found a XMP/RDF block
// Return the XMP text
$xmp_data = substr($jpeg_header_data[$i]['SegData'], 29);

return trim($xmp_data); // trim() should not be neccesary, but some files found in the wild with null-terminated block (known samples from Apple Aperture) causes problems elsewhere (see https://www.getid3.org/phpBB3/viewtopic.php?f=4&t=1153)
if (is_array($jpeg_header_data) && count($jpeg_header_data) > 0) {
foreach ($jpeg_header_data as $segment) {
// If we find an APP1 header,
if (strcmp($segment['SegName'], 'APP1') === 0) {
// And if it has the Adobe XMP/RDF label (http://ns.adobe.com/xap/1.0/\x00) ,
if (strncmp($segment['SegData'], 'http://ns.adobe.com/xap/1.0/' . "\x00", 29) === 0) {
// Found a XMP/RDF block
// Return the XMP text
$xmp_data = substr($segment['SegData'], 29);

// trim() should not be necessary, but some files found in the wild with null-terminated block
// (known samples from Apple Aperture) causes problems elsewhere
// (see https://www.getid3.org/phpBB3/viewtopic.php?f=4&t=1153)
return trim($xmp_data);
}
}
}
}

return false;
}

Expand All @@ -225,7 +228,7 @@ public function _get_XMP_text($filename)
* which contains all the XMP (XML) information.
*
* @param string $xmltext - a string containing the XMP data (XML) to be parsed
* @return array|boolean $xmp_array - an array containing all xmp details retrieved,
* @return array|false $xmp_array - an array containing all xmp details retrieved,
* FALSE - couldn't parse the XMP data.
*/
public function read_XMP_array_from_text($xmltext)
Expand Down

0 comments on commit 510a46d

Please sign in to comment.