Added image view, next/previous and view update

This commit is contained in:
Deon George 2016-06-29 20:49:02 +10:00
parent 3361427c75
commit c5f0bfffd0
6 changed files with 168 additions and 42 deletions

View File

@ -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.
}

View File

@ -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');
}
}

View File

@ -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]+');;

View File

@ -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;

View File

@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<title>Photo</title>
<!-- Fonts -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" integrity="sha384-XdYbMnZ/QjLh6iI4ogqCTaIjrFk87ip+ekIjefZch0Y+PvJ8CDYtEs1ipDmPorQ+" crossorigin="anonymous">
@ -40,7 +40,7 @@
<!-- Branding Image -->
<a class="navbar-brand" href="{{ url('/') }}">
Laravel
Photo
</a>
</div>

View File

@ -2,49 +2,81 @@
@section('content')
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">Photo <?php echo $photo->id; ?></div>
<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="panel-body">
<div class="col-md-2"><img src="/thumbnail/<?php echo $photo->id; ?>" width="200px"></div>
<div class="col-md-10">
<div class="dl-horizontal">
<dt>Filename</dt><dd><?php echo $photo->file_path(TRUE); ?></dd>
<?php if ($photo->shouldMove()) : ?>
<dt>NEW Filename</dt><dd><?php echo $photo->file_path(TRUE,TRUE); ?></dd>
<?php endif ?>
<br/>
<dt>Date Taken</dt><dd><?php echo $photo->date_taken(); ?></dd>
<dt>Camera</dt><dd><?php echo $photo->make; ?></dd>
<dt>Model</dt><dd><?php echo $photo->model; ?></dd>
<br/>
<dt>Location</dt><dd>
<?php if ($photo->gps() == 'UNKNOWN') : ?>
UNKNOWN
<?php else : ?>
<div id="map" style="width: 400px; height: 300px"></div>
<div class="panel-body">
<div class="col-md-2">
<a href="{{ url('/view/'.$photo->id) }}"><img src="{{ url('/thumbnail/'.$photo->id) }}" width="200px"></a>
<div class="text-center">
<ul class="pagination">
<li <?php if (! $x = $photo->previous()) : ?>class="disabled"<?php endif ?>><a href="{{ $x ? url('/info/'.$x->id) : '#' }}">&lt;&lt;</a></li>
<li <?php if (! $x = $photo->next()) : ?>class="disabled"<?php endif ?>><a href="{{ $x ? url('/info/'.$x->id) : '#' }}">&gt;&gt;</a></li>
</ul>
</div>
</div>
<div class="col-md-10">
<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->size() }}<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>
<br/>
<dt>Location</dt><dd>
<?php if ($photo->gps() == 'UNKNOWN') : ?>
UNKNOWN
<?php 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>
<script type="text/javascript">
var myLatLng = {lat: <?php echo $photo->gps_lat; ?>, lng: <?php echo $photo->gps_lon; ?>};
var myLatLng = {lat: {{ $photo->gps_lat }}, lng: {{ $photo->gps_lon }}};
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 16,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
zoom: 16,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
map: map,
position: myLatLng,
map: map,
position: myLatLng,
});
</script>
<?php endif ?>
</dd>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endif ?>
</dd>
<br/>
<dt>Exif Data</dt><dd>
<table>
<?php foreach ($photo->io()->getImageProperties() as $k => $v) : ?>
<?php if (in_array($k,['signature'])) continue ?>
<tr><th>{{ $k }}<><td>{{ $v }}<td></tr>
<?php endforeach ?>
</table>
</dd>
</div>
</div>
<?php if ($photo->remove) : ?>
<form action="{{ url('/undelete/'.$photo->id) }}" method="POST">
<button class="btn btn-default">Undelete</button>
<?php else : ?>
<form action="{{ url('/delete/'.$photo->id) }}" method="POST">
<button class="btn btn-default">Delete</button>
<?php endif ?>
{{ csrf_field() }}
</form>
</div>
</div>
</div>
</div>
</div>
@endsection