Skip to content

Commit

Permalink
Merge pull request #6 from xp-framework/feature/lens-model
Browse files Browse the repository at this point in the history
Read lens model and pass it to EXIF data
  • Loading branch information
thekid authored Jan 1, 2025
2 parents a6bd5df + e2ed911 commit e6569fd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/main/php/img/io/ExifSegment.class.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php namespace img\io;

use img\util\ExifData;

use util\Objects;

/**
* APP1: EXIF data meta data segment
Expand Down Expand Up @@ -328,7 +328,8 @@ class ExifSegment extends Segment {
0xA40A => 'Sharpness',
0xA40B => 'DeviceSettingDescription',
0xA40C => 'SubjectDistanceRange',
0xA420 => 'ImageUniqueID'
0xA420 => 'ImageUniqueID',
0xA434 => 'LensModel',
];

/**
Expand Down Expand Up @@ -583,7 +584,7 @@ public function rawData($arg= null) {
* @return string
*/
public function toString() {
return nameof($this).'<'.$this->marker.'>'.\xp::stringOf($this->data);
return nameof($this).'<'.$this->marker.'>'.Objects::stringOf($this->data);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/php/img/io/ImageMetaData.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public function exifData($tz= null) {
$data->withSoftware(null === ($l= self::lookup($raw, 'Software')) ? null : trim($l));

$exif= $raw['Exif_IFD_Pointer']['data'];
$data->withLensModel(null === ($l= self::lookup($exif, 'LensModel')) ? null : trim($l));

if ($sof= $this->segmentsOf(SOFNSegment::class)) {
$data->withWidth($sof[0]->width());
Expand Down Expand Up @@ -212,7 +213,8 @@ public function exifData($tz= null) {
$data->withFlash(self::lookup($exif, 'Flash'));

if (null !== ($date= self::lookup($exif, 'DateTimeOriginal', 'DateTimeDigitized', 'DateTime'))) {
$data->withDateTime(new Date($date, $tz));
sscanf($date, '%d:%d:%d %d:%d:%d', $year, $month, $day, $hour, $minute, $second);
$data->withDateTime(Date::create($year, $month, $day, $hour, $minute, $second, $tz));
}

if (null !== ($o= self::lookup($exif, 'Orientation'))) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/php/img/util/ExifData.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ExifData implements Value {
$width = 0,
$make = '',
$model = '',
$lensModel = '',
$flash = 0,
$orientation = 0,
$fileName = '',
Expand Down Expand Up @@ -79,6 +80,17 @@ public function withModel($model) {
return $this;
}

/**
* Set Lens Model
*
* @param string model
* @return self
*/
public function withLensModel($lensModel) {
$this->lensModel= $lensModel;
return $this;
}

/**
* Set Flash
*
Expand Down Expand Up @@ -375,6 +387,7 @@ public function toString() {
" [file ] %s (%d bytes)\n".
" [make ] %s\n".
" [model ] %s\n".
" [lensModel ] %s\n".
" [software ] %s\n".
" [flash ] %d (%s)\n".
" [orientation ] %s (%s, %s)\n".
Expand All @@ -395,6 +408,7 @@ public function toString() {
$this->fileSize,
$this->make,
$this->model,
$this->lensModel,
$this->software,
$this->flash,
$this->flashUsed() ? 'on' : 'off',
Expand Down

0 comments on commit e6569fd

Please sign in to comment.