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

@@ -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)
@@ -92,16 +98,15 @@ class Photo extends Abstracted\Catalog
$coordinate[$i] = 0;
}
list($degrees, $minutes, $seconds) = $coordinate;
list($degrees,$minutes,$seconds) = $coordinate;
$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));
}