Updated photo viewing
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user