Exif data now captures the taken date/time, camera make, model and software

This commit is contained in:
Andy Heathershaw 2016-09-02 22:18:40 +01:00
parent 6e04389e07
commit d559d09d55
4 changed files with 115 additions and 2 deletions

View File

@ -8,6 +8,12 @@ use Symfony\Component\HttpFoundation\File\File;
interface IAlbumSource
{
/**
* Gets the absolute path or URL to the given photo file.
* @param Album $album
* @param Photo $photo
* @return string
*/
function getPathToPhoto(Album $album, Photo $photo);
/**

View File

@ -12,6 +12,8 @@ use Illuminate\Support\Facades\Storage;
class ProcessUploadCommand extends Command
{
const METADATA_VERSION = 1;
/**
* The name and signature of the console command.
*
@ -68,6 +70,7 @@ class ProcessUploadCommand extends Command
private function handlePhoto(UploadPhoto $uploadPhoto)
{
/** @var Photo $photo */
$photo = $uploadPhoto->photo;
$this->output->writeln(sprintf('Analysing photo #%d: %s', $photo->id, $photo->name));
@ -77,6 +80,60 @@ class ProcessUploadCommand extends Command
$photoFile = $albumSource->getPathToPhoto($album, $photo);
dump(@exif_read_data($photoFile));
$exifData = @exif_read_data($photoFile);
dump($exifData);
$photo->metadata_version = ProcessUploadCommand::METADATA_VERSION;
$photo->taken_at = $this->metadataDateTime($exifData);
$photo->camera_make = $this->metadataCameraMake($exifData);
$photo->camera_model = $this->metadataCameraModel($exifData);
$photo->camera_software = $this->metadataCameraSoftware($exifData);
$photo->save();
}
private function metadataCameraMake(array $exifData)
{
if (isset($exifData['Make']))
{
return $exifData['Make'];
}
return null;
}
private function metadataCameraModel(array $exifData)
{
if (isset($exifData['Model']))
{
return $exifData['Model'];
}
return null;
}
private function metadataCameraSoftware(array $exifData)
{
if (isset($exifData['Software']))
{
return $exifData['Software'];
}
return null;
}
private function metadataDateTime(array $exifData)
{
$dateTime = null;
if (isset($exifData['DateTime']))
{
$dateTime = $exifData['DateTime'];
}
if (!is_null($dateTime))
{
$dateTime = preg_replace('/^([\d]{4}):([\d]{2}):([\d]{2})/', '$1-$2-$3', $dateTime);
}
return $dateTime;
}
}

View File

@ -15,7 +15,17 @@ class Photo extends Model
* @var array
*/
protected $fillable = [
'album_id', 'name', 'description', 'file_name', 'mime_type', 'file_size'
'album_id',
'name',
'description',
'file_name',
'mime_type',
'file_size',
'metadata_version',
'taken_at',
'camera_make',
'camera_model',
'camera_software'
];
/**

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddPhotoMetadataColumns extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('photos', function (Blueprint $table) {
$table->dateTime('taken_at')->nullable();
$table->integer('metadata_version')->nullable();
$table->string('camera_make')->nullable();
$table->string('camera_model')->nullable();
$table->string('camera_software')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('photos', function (Blueprint $table) {
$table->dropColumn('taken_at');
$table->dropColumn('metadata_version');
$table->dropColumn('camera_make');
$table->dropColumn('camera_model');
$table->dropColumn('camera_software');
});
}
}