#38: Made a few tweaks to the analysis function that doesn't delete the photo if it was previously analysed (i.e. it has a metadata version). Also if the original image contained Exif data (e.g. camera make), we no longer remove it if the re-analysed image doesn't (see #39)

This commit is contained in:
Andy Heathershaw 2017-09-16 09:02:25 +01:00
parent 4f7ad41009
commit 48f43b3c04
4 changed files with 64 additions and 17 deletions

View File

@ -59,8 +59,11 @@ class PhotoController extends Controller
$result['is_successful'] = false; $result['is_successful'] = false;
$result['message'] = $ex->getMessage(); $result['message'] = $ex->getMessage();
// Remove the photo if it cannot be analysed // Remove the photo if it cannot be analysed (only if there isn't currently a version of metadata)
$photo->delete(); if (is_null($photo->metadata_version))
{
$photo->delete();
}
} }
return response()->json($result); return response()->json($result);

View File

@ -108,10 +108,10 @@ class PhotoService
if ($isExifDataFound) if ($isExifDataFound)
{ {
$this->photo->metadata_version = self::METADATA_VERSION; $this->photo->metadata_version = self::METADATA_VERSION;
$this->photo->taken_at = $this->metadataDateTime($exifData); $this->photo->taken_at = $this->metadataDateTime($exifData, $this->photo->taken_at);
$this->photo->camera_make = $this->metadataCameraMake($exifData); $this->photo->camera_make = $this->metadataCameraMake($exifData, $this->photo->camera_make);
$this->photo->camera_model = $this->metadataCameraModel($exifData); $this->photo->camera_model = $this->metadataCameraModel($exifData, $this->photo->camera_model);
$this->photo->camera_software = $this->metadataCameraSoftware($exifData); $this->photo->camera_software = $this->metadataCameraSoftware($exifData, $this->photo->camera_software);
} }
$this->photo->is_analysed = true; $this->photo->is_analysed = true;
@ -301,37 +301,37 @@ class PhotoService
return $photoPath; return $photoPath;
} }
private function metadataCameraMake(array $exifData) private function metadataCameraMake(array $exifData, $originalValue = null)
{ {
if (isset($exifData['Make'])) if (isset($exifData['Make']))
{ {
return $exifData['Make']; return $exifData['Make'];
} }
return null; return $originalValue;
} }
private function metadataCameraModel(array $exifData) private function metadataCameraModel(array $exifData, $originalValue = null)
{ {
if (isset($exifData['Model'])) if (isset($exifData['Model']))
{ {
return $exifData['Model']; return $exifData['Model'];
} }
return null; return $originalValue;
} }
private function metadataCameraSoftware(array $exifData) private function metadataCameraSoftware(array $exifData, $originalValue = null)
{ {
if (isset($exifData['Software'])) if (isset($exifData['Software']))
{ {
return $exifData['Software']; return $exifData['Software'];
} }
return null; return $originalValue;
} }
private function metadataDateTime(array $exifData) private function metadataDateTime(array $exifData, $originalValue = null)
{ {
$dateTime = null; $dateTime = null;
if (isset($exifData['DateTimeOriginal'])) if (isset($exifData['DateTimeOriginal']))
@ -343,11 +343,11 @@ class PhotoService
$dateTime = $exifData['DateTime']; $dateTime = $exifData['DateTime'];
} }
if (!is_null($dateTime)) if (is_null($dateTime))
{ {
$dateTime = preg_replace('/^([\d]{4}):([\d]{2}):([\d]{2})/', '$1-$2-$3', $dateTime); return $originalValue;
} }
return $dateTime; return preg_replace('/^([\d]{4}):([\d]{2}):([\d]{2})/', '$1-$2-$3', $dateTime);
} }
} }

View File

@ -0,0 +1,34 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddPhotoExifDataColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('photos', function (Blueprint $table)
{
$table->longText('raw_exif_data');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('photos', function (Blueprint $table)
{
$table->dropColumn('raw_exif_data');
});
}
}

View File

@ -31,4 +31,14 @@
</div> </div>
</div> </div>
</div> </div>
@endsection @endsection
@push('scripts')
<script type="text/javascript">
$(document).ready(function() {
$('form').submit(function() {
$('button[type=submit]').prop('disabled', true);
});
});
</script>
@endpush