diff --git a/app/Console/Commands/Import.php b/app/Console/Commands/Import.php index 14299d2..9a052fd 100644 --- a/app/Console/Commands/Import.php +++ b/app/Console/Commands/Import.php @@ -151,7 +151,7 @@ class Import extends Command try { $po->thumbnail = exif_thumbnail($po->file_path()); - } catch (Exception $e) { + } catch (\Exception $e) { // @todo Couldnt get the thumbnail, so we should create one. } diff --git a/app/Http/Controllers/PhotoController.php b/app/Http/Controllers/PhotoController.php index 687a5e2..a57b83c 100644 --- a/app/Http/Controllers/PhotoController.php +++ b/app/Http/Controllers/PhotoController.php @@ -19,6 +19,19 @@ class PhotoController extends Controller $this->middleware('guest'); } + public function delete($id) + { + $po = Photo::notRemove()->findOrFail($id); + + if ($po) + { + $po->remove = TRUE; + $po->save(); + } + + return redirect()->action('PhotoController@info',[$id]); + } + public function info($id) { return view('photo.view', ['photo'=> Photo::findOrFail($id)]); @@ -26,6 +39,24 @@ class PhotoController extends Controller public function thumbnail($id) { - return (new Response(Photo::findOrFail($id)->thumbnail()))->header('Content-Type','image/jpg'); + return response(Photo::findOrFail($id)->thumbnail(TRUE))->header('Content-Type','image/jpeg'); + } + + public function undelete($id) + { + $po = Photo::findOrFail($id); + + if ($po) + { + $po->remove = NULL; + $po->save(); + } + + return redirect()->action('PhotoController@info',[$id]); + } + + public function view($id) + { + return response(Photo::findOrFail($id)->image())->header('Content-Type','image/jpeg'); } } diff --git a/app/Http/routes.php b/app/Http/routes.php index 8fa3ec9..9d248b4 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -21,3 +21,6 @@ Route::auth(); Route::get('/info/{id}', 'PhotoController@info')->where('id', '[0-9]+');; Route::get('/thumbnail/{id}', 'PhotoController@thumbnail')->where('id', '[0-9]+');; +Route::get('/view/{id}', 'PhotoController@view')->where('id', '[0-9]+');; +Route::post('/delete/{id}', 'PhotoController@delete')->where('id', '[0-9]+');; +Route::post('/undelete/{id}', 'PhotoController@undelete')->where('id', '[0-9]+');; diff --git a/app/Model/Photo.php b/app/Model/Photo.php index 8a7775f..537770b 100644 --- a/app/Model/Photo.php +++ b/app/Model/Photo.php @@ -77,6 +77,20 @@ class Photo extends Model return ($this->gps_lat AND $this->gps_lon) ? sprintf('%s/%s',$this->gps_lat,$this->gps_lon) : 'UNKNOWN'; } + /** + * Return the image, rotated, minus exif data + */ + public function image() { + $imo = $this->io(); + + if (array_key_exists('exif',$imo->getImageProfiles())) + $imo->removeImageProfile('exif'); + + $this->rotate($imo); + + return $imo->getImageBlob(); + } + /** * Return an Imagick object or attribute * @@ -146,6 +160,17 @@ class Photo extends Model return TRUE; } + /** + * Get the id of the previous photo + */ + public function next() + { + $po = DB::table('photo'); + $po->where('id','>',$this->id); + $po->orderby('id','ASC'); + return $po->first(); + } + /** * Rotate the image * @@ -158,10 +183,43 @@ class Photo extends Model return $imo->getImageBlob(); } - public static function path($path) { + public static function path($path) + { return preg_replace('/^\//','',str_replace(config('photo.dir'),'',$path)); } + /** + * Get the id of the previous photo + */ + public function previous() + { + $po = DB::table('photo'); + $po->where('id','<',$this->id); + $po->orderby('id','DEC'); + return $po->first(); + } + + /** + * Return the photo size + */ + public function size() + { + return filesize($this->file_path()); + } + + /** + * Display the photo signature + */ + public function signature($short=FALSE) + { + return $short ? static::signaturetrim($this->io()->getImageSignature()) : $this->io()->getImageSignature(); + } + + public static function signaturetrim($signature,$chars=6) + { + return sprintf('%s...%s',substr($signature,0,$chars),substr($signature,-1*$chars)); + } + /** * Determine if the image should be moved */ @@ -177,7 +235,9 @@ class Photo extends Model public function thumbnail($rotate=TRUE) { if (! $this->thumbnail) - return NULL; + { + return $this->io()->thumbnailimage(200,200,true,true) ? $this->io()->getImageBlob() : NULL; + } if (! $rotate OR ! array_key_exists($this->orientation,$this->_rotate) OR ! extension_loaded('imagick')) return $this->thumbnail; diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index d909843..e15706b 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -5,7 +5,7 @@ -
{{ $k }}<> | {{ $v }} |
---|