通用物体识别接口

@param string $image - 图像数据，base64编码，要求base64编码后大小不超过4M，最短边至少15px，最长边最大4096px,支持jpg/png/bmp格式
@param array $options - 可选参数对象，key: value都为string类型
@description options列表:
@return array
324797
public function advancedGeneral($image, $options=array()){

        $data = array();
        
        $data['image'] = base64_encode($image);

        $data = array_merge($data, $options);

        return $this->request($this->advancedGeneralUrl, $data);
    }
16847
public function execute($image)
    {
        $mode = $this->argument(0)->value('h');

        $size = $image->getSize();
        $dst = clone $size;

        switch (strtolower($mode)) {
            case 2:
            case 'v':
            case 'vert':
            case 'vertical':
                $size->pivot->y = $size->height - 1;
                $size->height = $size->height * (-1);
                break;

            default:
                $size->pivot->x = $size->width - 1;
                $size->width = $size->width * (-1);
                break;
        }

        return $this->modify($image, 0, 0, $size->pivot->x, $size->pivot->y, $dst->width, $dst->height, $size->width, $size->height);
    }
644590
public function fallbackImage($options = [], $image = [], $version = null) {
		if (isset($options['fallback'])) {
			if ($options['fallback'] === true) {
				$imageFile = 'placeholder/' . $version . '.jpg';
			} else {
				$imageFile = $options['fallback'];
			}
			unset($options['fallback']);

			return $this->Html->image($imageFile, $options);
		}

		return '';
	}
107395
public function lottery($image, $options=array()){

        $data = array();
        
        $data['image'] = base64_encode($image);

        $data = array_merge($data, $options);

        return $this->request($this->lotteryUrl, $data);
    }
160404
private function checkImageUrl($image)
    {
        if ( ! filter_var($image, FILTER_VALIDATE_URL)) {
            throw Exceptions\InvalidImageUrlException::make($image);
        }

        return $image;
    }
496615
public function getImageCaption($image): ?string
    {
        if (null === ($file = $this->container->get('huh.utils.file')->getFileFromUuid($image))) {
            return null;
        }

        $meta = StringUtil::deserialize($file->getModel()->meta, true);

        if (!isset($meta[$GLOBALS['TL_LANGUAGE']]['caption'])) {
            return null;
        }

        return $meta[$GLOBALS['TL_LANGUAGE']]['caption'];
    }
446398
public function carDetect($image, $options=array()){

        $data = array();
        
        $data['image'] = base64_encode($image);

        $data = array_merge($data, $options);

        return $this->request($this->carDetectUrl, $data);
    }
119526
public function optimize($image, $option = null)
    {
        // optimize: image optimization in the same format
        // webp: converts the image to the WebP image format
        if ($option === null) {
            $option = 'optimize';
        }

        $callApiUrl = $this->apiUrl . '/' . $this->username . '/' . $option;

        $blob = null;
        if (strpos($image, 'http')) {
            $blob = $this->fromUrl($image, $callApiUrl);
        } elseif (is_file($image)) {
            $blob = $this->fromFile($image, $callApiUrl);
        }

        return $blob;
    }
1005705
public function saveFromString($image, $options = array())
    {
        if (isset($options['file'])) {
            if (false === @file_put_contents($options['file'], $image)) {
                throw new Exception\RuntimeException('could not save image');
            }
            return $options['file'];
        }
        return $image;
    }
1073275
protected function crop($image, $options)
    {
        return $image->crop(new Point($options['point'][0], $options['point'][1]), new Box($options['box'][0], $options['box'][1]));
    }
799039
public function businessLicense($image, $options=array()){

        $data = array();
        
        $data['image'] = base64_encode($image);

        $data = array_merge($data, $options);

        return $this->request($this->businessLicenseUrl, $data);
    }
997934
public function plantDetect($image, $options=array()){

        $data = array();
        
        $data['image'] = base64_encode($image);

        $data = array_merge($data, $options);

        return $this->request($this->plantDetectUrl, $data);
    }
886644
public function execute($image)
    {
        $red = $this->argument(0)->between(-100, 100)->required()->value();
        $green = $this->argument(1)->between(-100, 100)->required()->value();
        $blue = $this->argument(2)->between(-100, 100)->required()->value();

        // normalize colorize levels
        $red = round($red * 2.55);
        $green = round($green * 2.55);
        $blue = round($blue * 2.55);

        // apply filter
        return imagefilter($image->getCore(), IMG_FILTER_COLORIZE, $red, $green, $blue);
    }
182861
public function optimize($image, $option = null)
    {
        // optimize: image optimization in the same format
        // webp: converts the image to the WebP image format
        if ($option === null) {
            $option = 'optimize';
        }

        $callApiUrl = $this->apiUrl . '/' . $this->apiKey . '?' . $option;

        $headers = [
            'User-Agent: Optimus-API',
            'Accept: image/*',
        ];

        $handle = curl_init();
        curl_setopt_array($handle, [
            CURLOPT_URL            => $callApiUrl,
            CURLOPT_HTTPHEADER     => $headers,
            CURLOPT_POSTFIELDS     => file_get_contents($image),
            CURLOPT_BINARYTRANSFER => true,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER         => true,
            CURLOPT_SSL_VERIFYPEER => true,
        ]);

        $response = curl_exec($handle);
        $curlError = curl_error($handle);
        $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
        $body = substr($response, $header_size);
        // error catching
        if ( ! empty($curlError) || empty($body)) {
            throw new RuntimeException("Optimus-Error: {$curlError}, Output: {$body}");
        }

        return $body;
    }
483921
public function custom($image, $templateSign, $options=array()){

        $data = array();
        
        $data['image'] = base64_encode($image);
        $data['templateSign'] = $templateSign;

        $data = array_merge($data, $options);

        return $this->request($this->customUrl, $data);
    }
1135004
public function getImageWidth($image): ?string
    {
        if (null === ($file = $this->container->get('huh.utils.file')->getFileFromUuid($image))) {
            return null;
        }

        return $file->width;
    }
1100485
static function cropImage($image, $params, $original_size, $crop_size)
    {
        $qulitity = isset($params['qulitity']) ? $params['qulitity'] : 100;
        $dst_width = isset($params['width']) ? $params['width'] : 90;
        $dst_height = isset($params['height']) ? $params['height'] : 105;

        $image = WEBPATH . $image;
        if (!file_exists($image))
        {
            return '错误，图片不存在！';
        }

        $image_info = getimagesize($image);

        if ($image_info["mime"] == "image/jpeg" || $image_info["mime"] == "image/gif" || $image_info["mime"] == "image/png")
        {
            /**
             * 计算实际裁剪区域，图片是否被缩放，如果不是真实大小，需要计算
             */
            if (isset($params['abs_width']))
            {
                $tmp_rate = $params['abs_width'] / $params['width'];
                $crop_size['left'] = $crop_size['left'] * $tmp_rate;
                $crop_size['top'] = $crop_size['top'] * $tmp_rate;
                $crop_size['width'] = $crop_size['width'] * $tmp_rate;
                $crop_size['height'] = $crop_size['height'] * $tmp_rate;
            }

            //裁剪
            $image_new = imagecreatetruecolor($dst_width, $dst_height);
            switch ($image_info["mime"])
            {
                case "image/jpeg":
                    $bin_ori = imagecreatefromjpeg($image);
                    break;
                case "image/gif":
                    $bin_ori = imagecreatefromgif($image);
                    break;
                case "image/png":
                    $bin_ori = imagecreatefrompng($image);
                    break;
            }

            imagecopyresampled($image_new, $bin_ori, 0, 0, $crop_size['left'], $crop_size['top'], $dst_width,
                $dst_height, $crop_size['width'], $crop_size['height']);
            $file_new = WEBPATH . $params['newfile'];
            if (!file_exists(dirname($file_new)))
            {
                mkdir(dirname($file_new), 0777, true);
            }

            return imagejpeg($image_new, $file_new, $qulitity);
        }
    }