public function ImgData::getData in Panopoly 8.2
Gets an image's IPTC data.
Parameters
string $uri: The uri of the image.
Return value
array The IPTC data, keyed by attribute.
See also
\PHPExif\Adapter\Native
File
- modules/
panopoly/ panopoly_media/ src/ ImgData.php, line 46
Class
- ImgData
- Reads IPTC image data.
Namespace
Drupal\panopoly_mediaCode
public function getData($uri) {
$data = [];
/** @var \Drupal\Core\File\FileSystemInterface $f */
$f = \Drupal::service('file_system');
$size = @getimagesize($f
->realpath($uri), $info);
// Ensure file and IPTC info is present.
if (!$size || !$info || !isset($info['APP13'])) {
return $data;
}
// Ensure IPTC could be parsed.
if (!($iptc = iptcparse($info["APP13"]))) {
return $data;
}
// Map attributes into sensible structure.
foreach ($this->iptcMapping as $name => $field) {
if (!isset($iptc[$field])) {
$data[$name] = NULL;
continue;
}
if (count($iptc[$field]) === 1) {
$val = trim(reset($iptc[$field]));
if (!empty($val)) {
$data[$name] = reset($iptc[$field]);
}
}
else {
$data[$name] = $iptc[$field];
}
}
return $data;
}