Updated photo viewing

This commit is contained in:
Deon George 2019-12-14 22:29:54 +11:00
parent 8f093f50b7
commit ebfdf3f7d5
10 changed files with 232 additions and 188 deletions

View File

@ -42,6 +42,11 @@ class LoginController extends Controller
*/
public function showLoginForm()
{
return view('adminlte::auth.login');
$login_note = '';
if (file_exists('login_note.txt'))
$login_note = file_get_contents('login_note.txt');
return view('adminlte::auth.login')->with('login_note',$login_note);
}
}

View File

@ -54,7 +54,7 @@ class PhotoController extends Controller
{
return view('catalog.duplicatereview',[
'return'=>url('/p/duplicates'),
'catalog'=>is_null($id) ? Photo::notRemove()->where('duplicate',1)->paginate(50) : Photo::where('id',$id)->paginate(1)
'catalog'=>is_null($id) ? Photo::notRemove()->where('duplicate',1)->with('software.model.make')->paginate(10) : Photo::where('id',$id)->paginate(1)
]);
}
@ -73,15 +73,15 @@ class PhotoController extends Controller
// Set if delete
$po->remove = $request->input('remove.'.$id) ? 1 : NULL;
$po->isDirty() AND $po->save();
$po->save();
}
return redirect()->action('PhotoController@duplicates','?page='.$request->input('page'));
}
public function info($id)
public function info(Photo $o)
{
return view('photo.view', ['photo'=> Photo::findOrFail($id)]);
return view('photo.view',['o'=>$o]);
}
public function thumbnail($id)

View File

@ -10,7 +10,7 @@ use App\Models\{Person,Tag};
abstract class Catalog extends Model
{
protected $dates = ['date_created'];
protected static $includeSubSecTime = FALSE;
public function people()
{
@ -22,6 +22,38 @@ abstract class Catalog extends Model
return $this->belongsToMany(Tag::class);
}
public function scopeDuplicates($query) {
if (! $this->exists)
return $query;
// Exclude this record
$query->where('id','<>',$this->attributes['id']);
// Exclude those marked as remove
$query->where(function ($q) {
$q->where('remove','<>',TRUE)
->orWhere('remove','=',NULL);
});
$query->where(function ($q) {
$q->where('signature','=',$this->attributes['signature'])
->orWhere('file_signature','=',$this->attributes['file_signature'])
// Where the signature is the same
->orWhere(function($q) {
// Or they have the same time taken with the same camera
if ($this->attributes['date_created'] AND $this->software_id) {
$q->where('date_created','=',$this->attributes['date_created'] ?: NULL);
if (static::$includeSubSecTime)
$q->where('subsectime','=',$this->attributes['subsectime'] ?: NULL);
$q->where('software_id','=',$this->attributes['software_id']);
}
});
});
}
/**
* Multimedia NOT duplicate.
*
@ -66,21 +98,35 @@ abstract class Catalog extends Model
abstract public function setDateCreated();
abstract public function setLocation();
abstract public function setMakeModel();
abstract public function setSignature();
abstract public function setSubSecTime();
abstract public function setThumbnail();
abstract public function view();
abstract public function getHtmlImageURL();
/**
* Date the multimedia was created
* @todo return Carbon date or NULL
*/
public function date_taken(): string
{
return $this->date_created ? date('Y-m-d H:i:s',$this->date_created) : 'UNKNOWN';
}
public function device(): string
{
$result = '';
if ($this->software->model->make)
$result .= $this->software->model->make->name;
if ($this->software->model)
$result .= ($result ? ' ' : '').$this->software->model->name;
if ($this->software)
$result .= ($result ? ' ' : '').$this->software->name;
return $result;
}
/**
* Return the date of the file
* @todo return Carbon date or NULL
@ -130,9 +176,9 @@ abstract class Catalog extends Model
/**
* Display the file signature
*/
public function file_signature($short=FALSE)
public function file_signature($short=FALSE): string
{
return $short ? static::signaturetrim($this->file_signature) : $this->file_signature;
return $short ? static::stringtrim($this->file_signature) : $this->file_signature;
}
/**
@ -349,7 +395,7 @@ abstract class Catalog extends Model
/**
* Determine if the image should be moved
*/
public function shouldMove(): boolean
public function shouldMove(): bool
{
return ($this->filename != $this->file_path(TRUE,TRUE));
}
@ -372,7 +418,7 @@ abstract class Catalog extends Model
/**
* Find duplicate images based on some attributes of the current image
* @todo Optimise this query
* @deprecate Use static::duplicates()
*/
public function list_duplicates($includeme=FALSE)
{

View File

@ -2,13 +2,15 @@
namespace App\Models;
use DB;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class Photo extends Abstracted\Catalog
{
protected $table = 'photo';
protected static $includeSubSecTime = TRUE;
// Imagick Object
private $_o;
@ -24,12 +26,19 @@ class Photo extends Abstracted\Catalog
return $this->belongsTo(Software::class);
}
public function getIDLinkAttribute()
{
return $this->HTMLLinkAttribute($this->id,url('p/info').'/');
}
/**
* Date the photo was taken
*/
public function date_taken(): string
{
return $this->date_created ? (date('Y-m-d H:i:s',$this->date_created).($this->subsectime ? '.'.$this->subsectime : '')) : 'UNKNOWN';
return $this->date_created
? ($this->date_created->format('Y-m-d H:i:s').($this->subsectime ? '.'.$this->subsectime : ''))
: 'UNKNOWN';
}
/**
@ -49,9 +58,9 @@ class Photo extends Abstracted\Catalog
return (($short OR preg_match('/^\//',$file)) ? '' : config('photo.dir').DIRECTORY_SEPARATOR).$file;
}
public function getIDLinkAttribute()
public function getHtmlImageURL(): string
{
return $this->HTMLLinkAttribute($this->id,url('p/info').'/');
return sprintf('<img height="240" src="%s"></img>',url('/p/thumbnail/'.$this->id));
}
/**
@ -65,9 +74,7 @@ class Photo extends Abstracted\Catalog
if (array_key_exists('exif',$imo->getImageProfiles()))
$imo->removeImageProfile('exif');
$this->rotate($imo);
return $imo->getImageBlob();
return $this->rotate($imo);
}
/**
@ -78,8 +85,7 @@ class Photo extends Abstracted\Catalog
if (! $coordinate OR ! $hemisphere)
return NULL;
for ($i=0; $i<3; $i++)
{
for ($i=0; $i<3; $i++) {
$part = explode('/', $coordinate[$i]);
if (count($part) == 1)
@ -96,12 +102,11 @@ class Photo extends Abstracted\Catalog
$sign = ($hemisphere == 'W' || $hemisphere == 'S') ? -1 : 1;
return round($sign*($degrees+$minutes/60+$seconds/3600),$degrees > 100 ? 3 : 4);
return round($sign*($degrees+$minutes/60+$seconds/3600),($degrees>100 ? 3 : 4));
}
/**
* Return an Imagick object or attribute
*
*/
protected function o($attr=NULL)
{
@ -123,8 +128,7 @@ class Photo extends Abstracted\Catalog
case 3: return 'Upside Down';
case 6: return 'Rotate Right';
case 8: return 'Rotate Left';
default:
return 'unknown?';
default: return 'unknown?';
}
}
@ -144,8 +148,7 @@ class Photo extends Abstracted\Catalog
if (! $this->o())
return NULL;
switch ($property)
{
switch ($property) {
case 'creationdate':
if ($this->property('exif:DateTimeOriginal') == '0000:00:00 00:00:00'
&& $this->property('exif:DateTimeOriginal') == '0000:00:00 00:00:00')
@ -172,6 +175,10 @@ class Photo extends Abstracted\Catalog
return $this->o() ? $this->_o->getImageProperties() : [];
}
public function getDateCreatedAttribute() {
return Carbon::createFromTimestamp($this->attributes['date_created']);
}
public function setDateCreated()
{
$this->date_created = $this->property('creationdate');
@ -181,9 +188,9 @@ class Photo extends Abstracted\Catalog
{
$this->gps_lat = static::latlon(preg_split('/,\s?/',$this->property('exif:GPSLatitude')),$this->property('exif:GPSLatitudeRef'));
$this->gps_lon = static::latlon(preg_split('/,\s?/',$this->property('exif:GPSLongitude')),$this->property('exif:GPSLongitudeRef'));
#$this->gps_altitude = $this->property('gps_altitude');
}
// @todo Now set software_id
public function setMakeModel()
{
$this->make = $this->property('exif:Make') ? $this->property('exif:Make') : NULL;
@ -195,7 +202,6 @@ class Photo extends Abstracted\Catalog
{
$this->signature = $this->property('signature');
$this->file_signature = md5_file($this->file_path());
#$this->identifier = $this->property('identifier');
}
public function setSubSecTime()
@ -211,6 +217,7 @@ class Photo extends Abstracted\Catalog
{
try {
$this->thumbnail = exif_thumbnail($this->file_path());
} catch (\Exception $e) {
// @todo Couldnt get the thumbnail, so we should create one.
Log::info(sprintf('Unable to create thumbnail for %s (%s)',$this->id,$e->getMessage()));
@ -225,8 +232,7 @@ class Photo extends Abstracted\Catalog
*/
public function thumbnail($rotate=TRUE)
{
if (! $this->thumbnail)
{
if (! $this->thumbnail) {
return $this->o()->thumbnailimage(200,200,true,true) ? $this->_o->getImageBlob() : NULL;
}
@ -247,9 +253,4 @@ class Photo extends Abstracted\Catalog
{
return strtolower($mime ? 'image/jpeg' : pathinfo($this->filename,PATHINFO_EXTENSION));
}
public function view()
{
return sprintf('<img height="240" src="%s"></img>',url('/p/thumbnail/'.$this->id));
}
}

View File

@ -132,6 +132,7 @@ class Video extends Abstracted\Catalog
$this->gps_altitude = $this->property('gps_altitude');
}
// @todo Now set software_id
public function setMakeModel()
{
$this->make = $this->property('make');
@ -170,7 +171,7 @@ class Video extends Abstracted\Catalog
return strtolower($mime ? File::mime_by_ext(pathinfo($this->filename,PATHINFO_EXTENSION)) : pathinfo($this->filename,PATHINFO_EXTENSION));
}
public function view()
public function getHtmlImageURL()
{
return sprintf('<video width="320" height="240" src="%s" controls></video>',url('/v/view/'.$this->id));
}

View File

@ -25,30 +25,20 @@
<table class="table table-striped table-sm table-hover table-bordered">
<thead>
<tr>
<th class="w-50">Source</th>
<th class="w-50">Remove</th>
<th class="w-50">Source</th>
</tr>
</thead>
@php $c=0; @endphp
@foreach ($catalog as $o)
@php
$d=$o->list_duplicates(TRUE); $src=[];
@endphp
<tbody>
<tr>
<td>
@if($d->where('duplicate',null)->count() > 1)
More than 1 source?
@elseif($d->count())
@php($src=$d->first())
@include('photo.widgets.thumbnail',['o'=>$src])
@endif
<input type="hidden" name="items[]" value="{{ $o->id }}">
@include('photo.widgets.thumbnail',['o'=>$o])
</td>
@if ($d->count() == 1)
@if (! ($d=$o->duplicates()->with('software.model.make')->get())->count())
<td>
No other duplicates found?
</td>
@ -56,22 +46,26 @@
@else
@foreach($d as $item)
@if($loop->first) @continue @endif
@php($diff=collect($src)->diffAssoc($item))
<td>
<input type="hidden" name="items[]" value="{{ $item->id }}">
XX
@include('photo.widgets.thumbnail',['o'=>$src])
@include('photo.widgets.thumbnail',['o'=>$item])
</td>
@endforeach
@endif
</tr>
</tbody>
@endforeach
<tfoot>
<tr>
<td colspan="2"><button class="btn btn-primary">Update</button></td>
</tr>
</tfoot>
</table>
{{--
<input type="hidden" name="pagenext" value="{{ $catalog->hasMorePages() ? $catalog->currentPage()+1 : NULL }}">
<button class="btn btn-primary">Update</button>
--}}
</form>
@else
NONE!

View File

@ -5,7 +5,7 @@
@endsection
@section('contentheader_title')
Photo
Photo #{{ $o->id }} @if($o->duplicate)<button class="btn btn-warning">DUPLICATE</button>@endif @if($o->remove)<button class="btn btn-danger">PENDING DELETE</button>@endif
@endsection
@section('contentheader_description')
#{{ $o->id }}
@ -16,46 +16,81 @@
@section('main-content')
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">
Photo {{ $photo->id }}<?php if ($photo->remove) : ?> - <strong>PENDING DELETE</strong><?php endif?>
</div>
<div class="col-3">
<a href="{{ url('p/view',$o->id) }}"><img class="p-3" src="{{ url('p/thumbnail',$o->id) }}"></a>
<div class="panel-body">
<div class="col-md-2">
<a href="{{ url('/p/view/'.$photo->id) }}"><img src="{{ url('/p/thumbnail/'.$photo->id) }}" width="200px"></a>
<div class="text-center">
<span class="pagination justify-content-center">
<nav>
<ul class="pagination">
<li <?php if (! $x = $photo->previous()) : ?>class="disabled"<?php endif ?>><a href="{{ $x ? url('/p/info/'.$x->id) : '#' }}">&lt;&lt;</a></li>
<li <?php if (! $x = $photo->next()) : ?>class="disabled"<?php endif ?>><a href="{{ $x ? url('/p/info/'.$x->id) : '#' }}">&gt;&gt;</a></li>
<li class="page-item @if(! $x=$o->previous())disabled @endif" aria-disabled="@if(! $x)true @else false @endif" aria-label="&laquo; Previous">
<a class="page-link" href="{{ $x ? url('p/info',$x->id) : '#' }}">&lt;&lt;</a>
</li>
<li class="page-item active" aria-current="page"><span class="page-link">{{ $o->id }}</span></li>
<li class="page-item @if(! $x=$o->next())disabled @endif" aria-disabled="@if(! $x)true @else false @endif" aria-label="&laquo; Previous">
<a class="page-link" href="{{ $x ? url('p/info',$x->id) : '#' }}">&gt;&gt;</a>
</li>
</ul>
</nav>
</span>
</div>
</div>
<div class="col-md-10">
<div class="col-9">
<div class="dl-horizontal">
<dt>Signature</dt><dd>{{ $photo->signature(TRUE) }}</dd>
<dt>Filename</dt><dd>{{ $photo->file_path(TRUE) }}<dd>
<?php if ($photo->shouldMove()) : ?>
<dt>NEW Filename</dt><dd>{{ $photo->file_path(TRUE,TRUE) }}<dd>
<?php endif ?>
<dt>Size</dt><dd>{{ $photo->file_size() }}<dd>
<dt>Dimensions</dt><dd>{{ $photo->width }} x {{ $photo->height }} @ {{ $photo->orientation }}<dd>
<br/>
<dt>Date Taken</dt><dd>{{ $photo->date_taken() }}<dd>
<dt>Camera</dt><dd>{{ $photo->make }}<dd>
<dt>Model</dt><dd>{{ $photo->model }}<dd>
<dt>Software</dt><dd>{{ $photo->software }}<dd>
<br/>
<dt>Signature</dt><dd>{{ $o->signature(TRUE) }}</dd>
<dt>Filename</dt><dd>{{ $o->file_path(TRUE) }}<dd>
@if ($o->shouldMove())
<dt>NEW Filename</dt><dd>{{ $o->file_path(TRUE,TRUE) }}<dd>
@endif
<dt>Size</dt><dd>{{ $o->file_size() }}<dd>
<dt>Dimensions</dt><dd>{{ $o->dimensions }} @ {{ $o->orientation }}<dd>
<hr>
<dt>Date Taken</dt><dd>{{ $o->date_taken() }}<dd>
<dt>Camera</dt><dd>{{ $o->device() }}<dd>
<hr>
<dt>Location</dt><dd>
<?php if ($photo->gps() == 'UNKNOWN') : ?>
@if($o->gps() == 'UNKNOWN')
UNKNOWN
<?php else : ?>
@else
<div id="map" style="width: 400px; height: 300px"></div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
@endif
</dd>
<br/>
<dt>Exif Data</dt><dd>
<table>
@foreach ($o->properties() as $k => $v)
<tr><th>{{ $k }}<><td>{{ $v }}<td></tr>
@endforeach
</table>
</dd>
</div>
@if ($o->remove)
<form action="{{ url('p/undelete',$o->id) }}" method="POST">
{{ csrf_field() }}
<button class="btn btn-primary">Undelete</button>
@else
<form action="{{ url('p/delete',$o->id) }}" method="POST">
{{ csrf_field() }}
<button class="btn btn-danger">Delete</button>
@endif
</form>
</div>
</div>
@endsection
@section('page-scripts')
@if($o->gps() !== 'UNKNOWN')
@js('//maps.google.com/maps/api/js?sensor=false')
<script type="text/javascript">
var myLatLng = {lat: {{ $photo->gps_lat }}, lng: {{ $photo->gps_lon }}};
var myLatLng = {lat: {{ $o->gps_lat }}, lng: {{ $o->gps_lon }}};
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 16,
center: myLatLng,
@ -66,30 +101,5 @@
position: myLatLng,
});
</script>
<?php endif ?>
</dd>
<br/>
<dt>Exif Data</dt><dd>
<table>
<?php foreach ($photo->properties() as $k => $v) : ?>
<tr><th>{{ $k }}<><td>{{ $v }}<td></tr>
<?php endforeach ?>
</table>
</dd>
</div>
</div>
<?php if ($photo->remove) : ?>
<form action="{{ url('/p/undelete/'.$photo->id) }}" method="POST">
<button class="btn btn-default">Undelete</button>
<?php else : ?>
<form action="{{ url('/p/delete/'.$photo->id) }}" method="POST">
<button class="btn btn-default">Delete</button>
<?php endif ?>
{{ csrf_field() }}
</form>
</div>
</div>
</div>
</div>
@endsection
@endif
@append

View File

@ -15,42 +15,29 @@
<div class="card-header">
<div class="user-block">
<i class="float-left fa fa-2x fa-camera"></i><span class="username"><a href="#">#{{ $o->id }} - {{ \Illuminate\Support\Str::limit($o->filename,12).\Illuminate\Support\Str::substr($o->filename,-16) }}</a></span>
<span class="description">{{ $o->date_created->toDateTimeString() }} [{{ $o->make }} {{ $o->model }} ({{ $o->software }})]</span>
<span class="description">{{ $o->date_created->toDateTimeString() }} [{{ $o->device() }}]</span>
</div>
<!-- /.user-block -->
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fa fa-minus"></i>
</button>
<button type="button" class="btn btn-tool" data-card-widget="remove"><i class="fa fa-times"></i>
</button>
<button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fa fa-minus"></i></button>
<button type="button" class="btn btn-tool" data-card-widget="remove"><i class="fa fa-times"></i></button>
</div>
<!-- /.card-tools -->
</div>
<!-- /.card-body -->
<div class="card-body">
{!! $o->view() !!}
{!! $o->getHtmlImageURL() !!}
<span class="float-right text-muted">&nbsp;</span>
</div>
<!-- /.card-body -->
<div class="card-footer card-comments">
<div class="card-comment">
<div class="comment-text">
<table class="table table-striped table-sm table-hover small">
@foreach($data as $k=>$v)
<tr><th>{{$k}}</th><td>{!! $src->{$v[1]} !!}</td></tr>
<tr><th>{{$k}}</th><td>{!! $o->{$v[1]} !!}</td></tr>
@endforeach
</table>
</div>
<!-- /.comment-text -->
</div>
<!-- /.card-comment -->
</div>
<!-- /.card-footer -->
<div class="card-footer">
</div>
<!-- /.card-footer -->
</div>

View File

@ -16,10 +16,10 @@ Route::get('/p/deletes/{id?}','PhotoController@deletes')->where('id','[0-9]+');
Route::get('/v/deletes/{id?}','VideoController@deletes')->where('id','[0-9]+');
Route::get('/p/duplicates/{id?}','PhotoController@duplicates')->where('id','[0-9]+');
Route::get('/v/duplicates/{id?}','VideoController@duplicates')->where('id','[0-9]+');
Route::get('/p/info/{id}','PhotoController@info')->where('id','[0-9]+');
Route::get('/p/info/{o}','PhotoController@info')->where('o','[0-9]+');
Route::get('/v/info/{id}','VideoController@info')->where('id','[0-9]+');
Route::get('/p/thumbnail/{id}','PhotoController@thumbnail')->where('id','[0-9]+');
Route::get('/p/view/{id}','PhotoController@view')->where('id','[0-9]+');
Route::get('/p/view/{o}','PhotoController@view')->where('o','[0-9]+');
Route::get('/v/view/{id}','VideoController@view')->where('id','[0-9]+');
Route::post('/p/delete/{id}','PhotoController@delete')->where('id','[0-9]+');