Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read lens model and pass it to EXIF data #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading