Exemplo n.º 1
0
 public function process($data)
 {
     $this->daemon->tick();
     //grab session id and number
     $data['message'] = array_merge(['count' => 1, 'mode' => 'photo', 'delay' => 0], $data['message']);
     $session = $data['message']['session'];
     $number = $data['message']['number'];
     $mode = $data['message']['mode'];
     $count = $data['message']['count'];
     $delay = $data['message']['delay'];
     if (!$session) {
         error_log('no session');
         return $this->daemon->run;
     }
     error_log('message data: ' . json_encode($data['message']));
     if ($delay) {
         sleep($delay);
     }
     //take photo
     switch ($mode) {
         case 'photo':
         default:
             error_log('taking photo');
             $this->gopro->shutter();
             sleep(2);
             break;
     }
     $last = $this->gopro->getLastFile(GoPro::FILTER_PHOTO);
     error_log('got last file: ' . $last);
     error_log('adding photo to session: ' . $last);
     $this->darkroom->addPhoto($session, $last, $number);
     $this->daemon->tick();
     return $this->daemon->run;
 }
Exemplo n.º 2
0
 public function __invoke($daemon)
 {
     error_log('checking gopro files');
     $imagine = $this->imagine;
     $new = [];
     foreach ($this->gopro->getFiles(GoPro::FILTER_PHOTO) as $file) {
         if (in_array($file->getSequence(), $this->list)) {
             continue;
         }
         $new[] = $file;
     }
     error_log('found files: ' . count($new));
     foreach ($new as $file) {
         error_log('downloading photo: ' . $file->getSequence());
         $content = $this->gopro->download($file);
         error_log('opening photo: ' . $file->getSequence());
         $photo = $imagine->load($content);
         error_log('resizing watermark');
         $watermark = $this->watermark->copy();
         $photoWidth = $photo->getSize();
         $waterSize = $watermark->getSize();
         $newSize = $waterSize->widen($photoWidth->getWidth() - 1);
         $watermark->resize($newSize);
         error_log('adding watermark');
         $pos = new Point(0, $photo->getSize()->getHeight() - $watermark->getSize()->getHeight());
         $photo->paste($watermark, $pos);
         error_log('uploading photo');
         $this->darkroom->upload($file, $photo->get('jpg'));
         error_log('resizing photo');
         $photo->resize(new Box($photo->getSize()->getWidth() / 4, $photo->getSize()->getHeight() / 4));
         error_log('uploading thumb');
         $this->darkroom->upload($file, $photo->get('jpg'), 'th');
         unset($photo);
         unset($watermark);
         $this->list[] = $file->getSequence();
     }
     if (!count($new)) {
         error_log('no new files, waiting a bit');
         sleep(60);
     }
     return true;
 }