Coverted script import to laravel
This commit is contained in:
9
app/Model/Person.php
Normal file
9
app/Model/Person.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Person extends Model
|
||||
{
|
||||
}
|
135
app/Model/Photo.php
Normal file
135
app/Model/Photo.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use DB;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Photo extends Model
|
||||
{
|
||||
protected $table = 'photo';
|
||||
|
||||
// Imagick Object
|
||||
private $_io;
|
||||
|
||||
// How should the image be rotated, based on the value of orientation
|
||||
private $_rotate = [
|
||||
3=>180,
|
||||
6=>90,
|
||||
8=>-90,
|
||||
];
|
||||
|
||||
/**
|
||||
* Determine the new name for the image
|
||||
*/
|
||||
public function file_path($short=FALSE,$new=FALSE) {
|
||||
$file = $this->filename;
|
||||
|
||||
if ($new)
|
||||
$file = sprintf('%s.%s',((is_null($this->date_taken) OR ! $this->date_taken)
|
||||
? sprintf('UNKNOWN/%07s',$this->file_path_id())
|
||||
: sprintf('%s_%03s',date('Y/m/d-His',$this->date_taken),$this->subsectime).($this->subsectime ? '' : sprintf('-%05s',$this->id))),$this->type());
|
||||
|
||||
return (($short OR preg_match('/^\//',$file)) ? '' : config('photo.dir').DIRECTORY_SEPARATOR).$file;
|
||||
}
|
||||
|
||||
public function gps(array $coordinate,$hemisphere) {
|
||||
if (! $coordinate OR ! $hemisphere)
|
||||
return NULL;
|
||||
|
||||
for ($i=0; $i<3; $i++) {
|
||||
$part = explode('/', $coordinate[$i]);
|
||||
|
||||
if (count($part) == 1)
|
||||
$coordinate[$i] = $part[0];
|
||||
|
||||
elseif (count($part) == 2)
|
||||
$coordinate[$i] = floatval($part[0])/floatval($part[1]);
|
||||
|
||||
else
|
||||
$coordinate[$i] = 0;
|
||||
}
|
||||
|
||||
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 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
|
||||
*
|
||||
*/
|
||||
private function rotate(\Imagick $imo)
|
||||
{
|
||||
if (array_key_exists($this->orientation,$this->_rotate))
|
||||
$imo->rotateImage(new \ImagickPixel('none'),$this->_rotate[$this->orientation]);
|
||||
|
||||
return $imo->getImageBlob();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the image's thumbnail
|
||||
*
|
||||
*/
|
||||
public function thumbnail($rotate=TRUE)
|
||||
{
|
||||
if (! $this->thumbnail)
|
||||
return NULL;
|
||||
|
||||
if (! $rotate OR ! array_key_exists($this->orientation,$this->_rotate) OR ! extension_loaded('imagick'))
|
||||
return $this->thumbnail;
|
||||
|
||||
$imo = new \Imagick();
|
||||
$imo->readImageBlob($this->thumbnail);
|
||||
|
||||
return $this->rotate($imo);
|
||||
}
|
||||
|
||||
public function list_duplicate() {
|
||||
$po = DB::table('photo');
|
||||
|
||||
if ($this->id)
|
||||
$po->where('id','!=',$this->id);
|
||||
|
||||
// Ignore photo's pending removal.
|
||||
$po->where(function($query) {
|
||||
$query->where('remove','!=',TRUE)
|
||||
->orWhere('remove','=',NULL);
|
||||
});
|
||||
|
||||
// Where the signature is the same
|
||||
$po->where(function($query) {
|
||||
$query->where('signature','=',$this->signature);
|
||||
|
||||
// Or they have the same time taken with the same camera
|
||||
if ($this->date_taken AND ($this->model OR $this->make)) {
|
||||
$query->orWhere(function($query) {
|
||||
$query->where('date_taken','=',$this->date_taken ? $this->date_taken : NULL);
|
||||
$query->where('subsectime','=',$this->subsectime ? $this->subsectime : NULL);
|
||||
|
||||
if (! is_null($this->model))
|
||||
$query->where('model','=',$this->model);
|
||||
|
||||
if (! is_null($this->make))
|
||||
$query->where('make','=',$this->make);
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return $po;
|
||||
}
|
||||
}
|
9
app/Model/PhotoPerson.php
Normal file
9
app/Model/PhotoPerson.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PhotoPerson extends Model
|
||||
{
|
||||
}
|
15
app/Model/PhotoTag.php
Normal file
15
app/Model/PhotoTag.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PhotoTag extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'photo_tag';
|
||||
}
|
9
app/Model/Tag.php
Normal file
9
app/Model/Tag.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Tag extends Model
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user