/**
  * Route to analyze images and get a JSON result.  This is the main doorway
  * for clients to submit their images for analysis.
  * 
  * @return json
  */
 public function get_analysis()
 {
     //Validate account
     $account = Input::get('account');
     $token = Input::get('token');
     $validate = true;
     //$this->account->validateCredentials($account, $token);
     $rest = (object) 'Rest';
     if (!$validate) {
         //Login failed.
         $rest->status = 'error';
         $rest->message = 'Login credentials are not valid.';
     } else {
         try {
             //collect results
             $data = array();
             //Get average color of sample
             if (Input::has('subject')) {
                 $sample = RemoteImage::create(Input::get('subject'));
                 $data['origin'] = $sample->getRgba()->toArray();
             }
             //If scale set, get colors from scale
             if (Input::has('palette_id')) {
                 $palette = Palette::find(Input::get('palette_id'))->colors()->get();
                 foreach ($palette as $color) {
                     $data['palette'][] = array('color' => $color->getRgba()->toArray(), 'variance' => CreateVarianceCtx::create($color->getRgba(), $sample->getRgba())->execute()->toArray());
                 }
                 unset($color);
             }
             //*
             usort($data['palette'], function ($a, $b) {
                 return strcmp($a['variance']['magnitude'], $b['variance']['magnitude']);
             });
             /*
             				$data['ambient']['color'] = $this->litmus->adjust_ambient(
             						$data['sample']['color'],
             						$this->control_captured,
             						$this->control_actual
             					);
             //*/
             //return result object
             $time = date('M d, Y H:i:s');
             $rest->status = 'success';
             $rest->data = $data;
             $rest->message = 'Account: ' . $account . ' @ ' . $time;
         } catch (Exception $e) {
             $rest->status = 'error';
             $rest->message = $e->getMessage();
         }
         // end try/catch
     }
     //end if/else
     return Response::json($rest);
 }
Exemple #2
0
 /**
  * Compares this color's Rgba object to another Rgba object and returns
  * a Variance object.
  * 
  * @param  Rgba 		$rgba Rgba object to compare this colors Rgba object to.
  * @return Variance 	Returns Variance object.
  */
 public function compareTo(Rgba $rgba)
 {
     $this->variance = CreateVarianceCtx::create($this->getRgba(), $rgba)->execute();
     return $this;
 }