array('through'=>'album_photo'), 'people'=>array('through'=>'people_photo','far_key'=>'people_id'), ); /** * Filters used to format the display of values into friendlier values */ protected $_display_filters = array( 'date_orig'=>array( array('Site::Datetime',array(':value')), ), 'date_taken'=>array( array('Site::Datetime',array(':value')), ), 'signature'=>array( array('Model_Photo::Signaturetrim',array(':value')), ), ); public function duplicate_find() { $po = ORM::factory($this->_object_name); if ($this->loaded()) $po->where('id','!=',$this->id); $po->where_open(); $po->where('delete','!=',TRUE); $po->or_where('delete','is',NULL); $po->where_close(); $po->where_open(); $po->where('signature','=',$this->signature); if ($this->date_taken AND ($this->model OR $this->make)) { $po->or_where_open(); $po->where('date_taken','=',$this->date_taken); $po->where('subsectime','=',$this->subsectime); if (! is_null($this->model)) $po->and_where('model','=',$this->model); if (! is_null($this->make)) $po->and_where('make','=',$this->make); $po->where_close(); } $po->where_close(); return $po; } public function date_taken() { return $this->display('date_taken').($this->subsectime ? '.'.$this->subsectime : ''); } public function duplicate_get() { return $this->duplicate_find()->find_all(); } 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); } public function image() { $imo = $this->io(); $imo->removeImageProfile('exif'); $this->rotate($imo); return $imo->getImageBlob(); } public function info() { $imo = $this->io(); return $imo->getImageProperties(); } public function io($attr=NULL) { if (is_nulL($this->_io)) $this->_io = new Imagick($this->path.'/'.$this->filename); return is_null($attr) ? $this->_io : $this->_io->getImageProperty($attr); } public function path() { $path = ''; $ao = $this->album->where('primary','=',TRUE)->find(); if ($ao->loaded()) { $path .= $ao->path.'/'; if ($ao->subpath_age) { $po = $this->people->where('primary','=',TRUE)->find(); $path .= $po->age($this->date_taken).'/'; } } $path .= sprintf('%s_%03s.%s',date('Ymd-His',$this->date_taken),$this->subsectime,$this->type()); return $path; } private function rotate(Imagick $imo) { switch ($this->orientation) { case 3: $imo->rotateImage(new ImagickPixel('none'),180); break; case 6: $imo->rotateImage(new ImagickPixel('none'),90); break; case 8: $imo->rotateImage(new ImagickPixel('none'),-90); break; } } public static function Signaturetrim($signature) { return sprintf('%s...%s',substr($signature,0,6),substr($signature,-6)); } public function thumbnail() { $imo = new Imagick(); $imo->readImageBlob($this->thumbnail); $this->rotate($imo); return $imo->getImageBlob(); } public function type($mime=FALSE) { return strtolower($mime ? File::mime_by_ext(pathinfo($this->filename,PATHINFO_EXTENSION)) : pathinfo($this->filename,PATHINFO_EXTENSION)); } } ?>