Skip to content

Commit

Permalink
Show lens model and creatiom date from EXIF / XMP segments
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Jan 1, 2025
1 parent ed4b889 commit 49d86a5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"require": {
"xp-framework/compiler": "^9.3",
"xp-framework/imaging": "^11.0",
"xp-framework/imaging": "^11.1",
"xp-framework/command": "^12.0",
"xp-framework/networking": "^10.4",
"xp-forge/marshalling": "^2.4",
Expand Down
14 changes: 10 additions & 4 deletions src/main/handlebars/layout.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@
left: 0;
font-size: .9rem;
display: grid;
grid-template-columns: repeat(6, max-content);
grid-template-columns: repeat(8, max-content);
gap: 1px;
justify-content: center;
pointer-events: none;
Expand Down Expand Up @@ -747,7 +747,7 @@
max-width: 100%;
.meta {
grid-template-columns: repeat(3, max-content) 1fr;
grid-template-columns: repeat(4, 1fr);
transform: scale(1, 1);
gap: 0;
background-color: white;
Expand All @@ -761,8 +761,12 @@
border-radius: 0;
}
.meta div:nth-child(2) {
grid-column: span 3;
.meta div:nth-child(1) {
grid-column: span 2;
}
.meta div:nth-child(4) {
grid-column: span 4;
}
.meta div {
Expand Down Expand Up @@ -811,8 +815,10 @@
<div class="image">
<img alt="Lightbox" width="100%">
<div class="meta">
<div><output name="datetime"></output></div>
<div><output name="make"></output></div>
<div><output name="model"></output></div>
<div><output name="lensmodel"></output></div>
<div>ISO <output name="isospeedratings"></output></div>
<div><output name="focallength"></output> mm</div>
<div><output name="aperturefnumber"></output></div>
Expand Down
13 changes: 11 additions & 2 deletions src/main/php/de/thekid/dialog/processing/Images.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php namespace de\thekid\dialog\processing;

use img\io\MetaDataReader;
use img\io\{MetaDataReader, XMPSegment};
use io\File;

class Images extends Processing {
private const RDF= 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
private $meta= new MetaDataReader();

public function kind(): string { return 'image'; }
Expand All @@ -24,16 +25,24 @@ public function meta(File $source): array<string, mixed> {
$r+= [
'width' => $exif->width,
'height' => $exif->height,
'dateTime' => $exif->dateTime?->toString('c', self::$UTC) ?? gmdate('c'),
'dateTime' => $exif->dateTime?->toString(self::DATEFORMAT),
'make' => $exif->make,
'model' => $exif->model,
'lensModel' => $exif->lensModel,
'apertureFNumber' => $exif->apertureFNumber,
'exposureTime' => $exif->exposureTime,
'isoSpeedRatings' => $exif->isoSpeedRatings,
'focalLength' => $exif->focalLength ? $this->toRounded($exif->focalLength, precision: 1) : null,
'flashUsed' => $exif->flashUsed(),
];
}

// Merge in XMP segment
if ($xmp= $meta?->segmentsOf(XMPSegment::class)) {
foreach ($xmp[0]->document()->getElementsByTagNameNS(self::RDF, 'Description')[0]->attributes as $attr) {
$r[lcfirst($attr->name)]= $attr->value;
}
}
return $r;
} finally {
$source->close();
Expand Down
2 changes: 1 addition & 1 deletion src/main/php/de/thekid/dialog/processing/Processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use util\TimeZone;

abstract class Processing {
protected static $UTC= new TimeZone('UTC');
protected const DATEFORMAT= 'd.m.Y H:i';
protected $targets= [];

/** Returns processing kind */
Expand Down
8 changes: 4 additions & 4 deletions src/main/php/de/thekid/dialog/processing/Videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private function execute(string $command, array<string> $args): void {
}

public function meta(File $source): array<string, mixed> {
static $MAP= [
static $mdta= [
'mdta:com.apple.quicktime.make' => 'make',
'mdta:com.apple.quicktime.model' => 'model',
'mdta:com.android.manufacturer' => 'make',
Expand All @@ -49,21 +49,21 @@ public function meta(File $source): array<string, mixed> {
// Normalize meta data from iOS and Android devices
$r= [];
foreach ($meta as $key => $value) {
if ($mapped= $MAP[$key] ?? null) {
if ($mapped= $mdta[$key] ?? null) {
$r[$mapped]= $value[0];
}
}

// Prefer original creation date from iOS, converting it to local time
if ($date= $meta['mdta:com.apple.quicktime.creationdate'][0] ?? null) {
$r['dateTime']= new Date(preg_replace('/[+-][0-9]{4}$/', '', $date))->toString('c', self::$UTC);
$r['dateTime']= new Date(preg_replace('/[+-][0-9]{4}$/', '', $date))->toString(self::DATEFORMAT);
}

// Aggregate information from movie header: Duration and creation time
// Time info is the number of seconds since 1904-01-01 00:00:00 UTC
if (isset($meta['mvhd'])) {
$r['duration']= round($meta['mvhd']['duration'] / $meta['mvhd']['scale'], 3);
$r['dateTime']??= new Date($meta['mvhd']['created'] - 2082844800)->toString('c', self::$UTC);
$r['dateTime']??= new Date($meta['mvhd']['created'] - 2082844800)->toString(self::DATEFORMAT);
}

return $r;
Expand Down

0 comments on commit 49d86a5

Please sign in to comment.