mirror of
https://github.com/getgrav/grav.git
synced 2026-03-04 19:41:36 +01:00
Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -16,7 +16,7 @@ class Exif
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (function_exists('exif_read_data')) {
|
||||
if (function_exists('exif_read_data') && class_exists('\PHPExif\Reader\Reader')) {
|
||||
$this->reader = \PHPExif\Reader\Reader::factory(\PHPExif\Reader\Reader::TYPE_NATIVE);
|
||||
} else {
|
||||
if (Grav::instance()['config']->get('system.media.auto_metadata_exif')) {
|
||||
|
||||
@@ -21,6 +21,8 @@ class Media extends AbstractMedia
|
||||
|
||||
protected $path;
|
||||
|
||||
protected $standard_exif = ['FileSize', 'MimeType', 'height', 'width'];
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
*/
|
||||
@@ -124,13 +126,17 @@ class Media extends AbstractMedia
|
||||
// Read/store Exif metadata as required
|
||||
if (!empty($types['base']) && $medium->get('mime') === 'image/jpeg' && empty($types['meta']) && $config->get('system.media.auto_metadata_exif')) {
|
||||
$file_path = $types['base']['file'];
|
||||
$meta_path = $file_path . '.meta.yaml';
|
||||
$meta = $exif->reader->read($file_path);
|
||||
|
||||
if ($meta) {
|
||||
$file = File::instance($meta_path);
|
||||
$file->save(Yaml::dump($meta->getData()));
|
||||
$types['meta']['file'] = $meta_path;
|
||||
$meta_path = $file_path . '.meta.yaml';
|
||||
$meta_data = $meta->getData();
|
||||
$meta_trimmed = array_diff_key($meta_data, array_flip($this->standard_exif));
|
||||
if ($meta_trimmed) {
|
||||
$file = File::instance($meta_path);
|
||||
$file->save(Yaml::dump($meta_trimmed));
|
||||
$types['meta']['file'] = $meta_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,11 @@ class Medium extends Data implements RenderableInterface
|
||||
*/
|
||||
protected $styleAttributes = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $metadata = [];
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
@@ -77,6 +82,16 @@ class Medium extends Data implements RenderableInterface
|
||||
return new Data($this->items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing just the metadata
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function metadata()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta file for the medium.
|
||||
*
|
||||
@@ -84,7 +99,8 @@ class Medium extends Data implements RenderableInterface
|
||||
*/
|
||||
public function addMetaFile($filepath)
|
||||
{
|
||||
$this->merge((array)CompiledYamlFile::instance($filepath)->content());
|
||||
$this->metadata = (array)CompiledYamlFile::instance($filepath)->content();
|
||||
$this->merge($this->metadata);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user