diff --git a/app/Console/Commands/Import.php b/app/Console/Commands/Import.php index d975afc..bac1a8b 100644 --- a/app/Console/Commands/Import.php +++ b/app/Console/Commands/Import.php @@ -144,8 +144,8 @@ class Import extends Command $po->width = $po->io()->getImageWidth(); $po->orientation = $po->io()->getImageOrientation(); - $po->gps_lat = $po->gps(preg_split('/,\s?/',$po->io()->getImageProperty('exif:GPSLatitude')),$po->io()->getImageProperty('exif:GPSLatitudeRef')); - $po->gps_lon = $po->gps(preg_split('/,\s?/',$po->io()->getImageProperty('exif:GPSLongitude')),$po->io()->getImageProperty('exif:GPSLongitudeRef')); + $po->gps_lat = $po->latlon(preg_split('/,\s?/',$po->io()->getImageProperty('exif:GPSLatitude')),$po->io()->getImageProperty('exif:GPSLatitudeRef')); + $po->gps_lon = $po->latlon(preg_split('/,\s?/',$po->io()->getImageProperty('exif:GPSLongitude')),$po->io()->getImageProperty('exif:GPSLongitudeRef')); try { $po->thumbnail = exif_thumbnail($po->file_path()); diff --git a/app/Model/Photo.php b/app/Model/Photo.php index efc0031..34f74c9 100644 --- a/app/Model/Photo.php +++ b/app/Model/Photo.php @@ -19,6 +19,10 @@ class Photo extends Model 8=>-90, ]; + public function date_taken() { + return $this->date_taken ? (date('Y-m-d H:i:s',$this->date_taken).($this->subsectime ? '.'.$this->subsectime : '')) : 'UNKNOWN'; + } + /** * Determine the new name for the image */ @@ -33,7 +37,35 @@ class Photo extends Model return (($short OR preg_match('/^\//',$file)) ? '' : config('photo.dir').DIRECTORY_SEPARATOR).$file; } - public function gps(array $coordinate,$hemisphere) { + /** + * Calculate a file path ID based on the id of the file + */ + public function file_path_id($sep=3,$depth=9) { + return trim(chunk_split(sprintf("%0{$depth}s",$this->id),$sep,'/'),'/'); + } + + /** + * Display the GPS coordinates + */ + public function gps() { + return ($this->gps_lat AND $this->gps_lon) ? sprintf('%s/%s',$this->gps_lat,$this->gps_lon) : 'UNKNOWN'; + } + + /** + * Return an Imagick object or attribute + * + */ + public function io($attr=NULL) { + if (is_null($this->_io)) + $this->_io = new \Imagick($this->file_path()); + + return is_null($attr) ? $this->_io : $this->_io->getImageProperty($attr); + } + + /** + * Calculate the GPS coordinates + */ + public function latlon(array $coordinate,$hemisphere) { if (! $coordinate OR ! $hemisphere) return NULL; @@ -57,17 +89,6 @@ class Photo extends Model return round($sign*($degrees+$minutes/60+$seconds/3600),$degrees > 100 ? 3 : 4); } - /** - * Return an Imagick object or attribute - * - */ - public function io($attr=NULL) { - if (is_null($this->_io)) - $this->_io = new \Imagick($this->file_path()); - - return is_null($attr) ? $this->_io : $this->_io->getImageProperty($attr); - } - /** * Rotate the image * @@ -80,6 +101,14 @@ class Photo extends Model return $imo->getImageBlob(); } + /** + * Determine if the image should be moved + */ + public function shouldMove() + { + return ($this->filename != $this->file_path(TRUE,TRUE)); + } + /** * Return the image's thumbnail * @@ -98,6 +127,16 @@ class Photo extends Model return $this->rotate($imo); } + /** + * Return the extension of the image + */ + public function type($mime=FALSE) { + return strtolower($mime ? File::mime_by_ext(pathinfo($this->filename,PATHINFO_EXTENSION)) : pathinfo($this->filename,PATHINFO_EXTENSION)); + } + + /** + * Find duplicate images based on some attributes of the current image + */ public function list_duplicate() { $po = DB::table('photo'); diff --git a/resources/views/photo/view.blade.php b/resources/views/photo/view.blade.php index e5ebfd8..44dd991 100644 --- a/resources/views/photo/view.blade.php +++ b/resources/views/photo/view.blade.php @@ -8,7 +8,40 @@
Photo id; ?>
- +
+
+
+
Filename
file_path(TRUE); ?>
+ shouldMove()) : ?> +
NEW Filename
file_path(TRUE,TRUE); ?>
+ +
+
Date Taken
date_taken(); ?>
+
Camera
make; ?>
+
Model
model; ?>
+
+
Location
+ gps() == 'UNKNOWN') : ?> + UNKNOWN + +
+ + + +
+
+