Ejemplo n.º 1
0
 /**
  * Checks image limits, depending on the recognition mode
  *
  * @param Image $image the path to the file
  * @param string $mode the recognition mode
  * @return bool
  */
 public function imageLimitsCorrect(Image $image, $mode = 'single')
 {
     if (!in_array($mode, array('single', 'multi'))) {
         throw new RecognizeImException('Wrong "mode" value. Should be "single" or "multi"');
     }
     $size = filesize($image->getPath()) / 1000.0;
     // KB
     $dimensions = getimagesize($image->getPath());
     $width = $dimensions[0];
     $height = $dimensions[1];
     $surface = $width * $height / 1000000.0;
     // Mpix
     if ($mode === 'single') {
         if ($size > Configuration::SINGLEIR_MAX_FILE_SIZE || $height < Configuration::SINGLEIR_MIN_DIMENSION || $width < Configuration::SINGLEIR_MIN_DIMENSION || $surface < Configuration::SINGLEIR_MIN_IMAGE_SURFACE || $surface > Configuration::SINGLEIR_MAX_IMAGE_SURFACE) {
             return false;
         }
     } else {
         if ($size > Configuration::MULTIIR_MAX_FILE_SIZE || $height < Configuration::MULTIIR_MIN_DIMENSION || $width < Configuration::MULTIIR_MIN_DIMENSION || $surface < Configuration::MULTIIR_MIN_IMAGE_SURFACE || $surface > Configuration::MULTIIR_MAX_IMAGE_SURFACE) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * @param string $file
  * @return bool|string
  */
 public function drawFrames(Image $file, RecognizeResult $recognizeResult)
 {
     $im = imagecreatefromstring($file->getFileContents());
     if (false === $im) {
         throw new RecognizeImException('Image type is unsupported, the data is not in a recognised ' . 'format, or the image is corrupt and cannot be loaded.');
     }
     $color = imagecolorallocate($im, 255, 255, 255);
     /** @var RecognizedImage $object */
     foreach ($recognizeResult->getObjects() as $object) {
         $location = $object->getLocation();
         $size = count($location);
         for ($i = 0; $i < $size; ++$i) {
             $p1 = $location[$i];
             $p2 = $location[($i + 1) % $size];
             imageline($im, $p1['x'], $p1['y'], $p2['x'], $p2['y'], $color);
         }
     }
     ob_start();
     imagejpeg($im);
     $img = ob_get_clean();
     imagedestroy($im);
     return $img;
 }
Ejemplo n.º 3
0
 /**
  * Upload an image to images collection
  *
  * @param string $id
  * @param string $name
  * @param Image $data
  * @throws SoapApiException
  */
 public function imageInsert($id, $name, Image $data)
 {
     $result = new SoapRequestResult($this->soapClient->imageInsert($id, $name, base64_encode($data->getFileContents())));
     $this->checkRequestResultSuccess($result);
 }