自定义模板文字识别接口

@param string $image - 图像数据，base64编码，要求base64编码后大小不超过4M，最短边至少15px，最长边最大4096px,支持jpg/png/bmp格式
@param string $templateSign - 您在自定义文字识别平台制作的模板的ID
@param array $options - 可选参数对象，key: value都为string类型
@description options列表:
@return array
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);
    }
300351
public function bankcard($image, $options=array()){

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

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

        return $this->request($this->bankcardUrl, $data);
    }
611403
protected function gdLine($image, $num = 4)
    {
        for ($i = 0; $i <= $num; $i++) {
            $randcolor = $this->randColor();
            $color     = imagecolorallocate($image, hexdec(substr($randcolor, 1, 2)), hexdec(substr($randcolor, 3, 2)), hexdec(substr($randcolor, 5, 2)));
            //设置颜色
            $x1 = rand(0, $this->width);
            $y1 = rand(0, $this->height);
            $x2 = rand(0, $this->width);
            $y2 = rand(0, $this->height);
            imageline($image, $x1, $y1, $x2, $y2, $color);
        }
    }
814279
public function load(ImageInterface $image, array $options = [])
    {
        $options += [
            'size' => null,
            'position' => 'center',
        ];

        if ('%' === mb_substr($options['size'], -1)) {
            $options['size'] = mb_substr($options['size'], 0, -1) / 100;
        }

        $watermark = $this->imagine->open($this->rootPath.'/'.$options['image']);

        $size = $image->getSize();
        $watermarkSize = $watermark->getSize();

        // If 'null': Downscale if needed
        if (!$options['size'] && ($size->getWidth() < $watermarkSize->getWidth() || $size->getHeight() < $watermarkSize->getHeight())) {
            $options['size'] = 1.0;
        }

        if ($options['size']) {
            $factor = $options['size'] * min($size->getWidth() / $watermarkSize->getWidth(), $size->getHeight() / $watermarkSize->getHeight());

            $watermark->resize(new Box($watermarkSize->getWidth() * $factor, $watermarkSize->getHeight() * $factor));
            $watermarkSize = $watermark->getSize();
        }

        switch ($options['position']) {
            case 'topleft':
                $x = 0;
                $y = 0;
                break;
            case 'top':
                $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
                $y = 0;
                break;
            case 'topright':
                $x = $size->getWidth() - $watermarkSize->getWidth();
                $y = 0;
                break;
            case 'left':
                $x = 0;
                $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
                break;
            case 'center':
                $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
                $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
                break;
            case 'right':
                $x = $size->getWidth() - $watermarkSize->getWidth();
                $y = ($size->getHeight() - $watermarkSize->getHeight()) / 2;
                break;
            case 'bottomleft':
                $x = 0;
                $y = $size->getHeight() - $watermarkSize->getHeight();
                break;
            case 'bottom':
                $x = ($size->getWidth() - $watermarkSize->getWidth()) / 2;
                $y = $size->getHeight() - $watermarkSize->getHeight();
                break;
            case 'bottomright':
                $x = $size->getWidth() - $watermarkSize->getWidth();
                $y = $size->getHeight() - $watermarkSize->getHeight();
                break;
            default:
                throw new \InvalidArgumentException("Unexpected position '{$options['position']}'");
                break;
        }

        return $image->paste($watermark, new Point($x, $y));
    }
466520
public function thumbnailPath($image, $template)
    {
        if (!$image || !$template) {
            return '';
        }

        $parts = explode(';', $image);
        $fileId = $parts[0];

        $src = $this->router->generate('frontendmedia_thumbnail', ['fileId' => $fileId, 'template' => $template], UrlGeneratorInterface::ABSOLUTE_PATH);

        return $src;
    }
772537
public function load(ImageInterface $image, array $options = [])
    {
        $x = isset($options['start'][0]) ? $options['start'][0] : null;
        $y = isset($options['start'][1]) ? $options['start'][1] : null;

        $destImage = $this->imagine->open($this->rootPath.'/'.$options['image']);

        return $image->paste($destImage, new Point($x, $y));
    }
753207
public function productDeleteByImage($image, $options=array()){

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

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

        return $this->request($this->productDeleteUrl, $data);
    }
87982
public function save($image, $options)
    {
        $image = $this->saveToString($image, $options);
        return $this->saveFromString($image, $options);
    }
3114
public static function getImageInfo($image, array $config = null)
    {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $img = new static($image['value'], $finfo, $config);

        $curl = $img->getConnection();
        curl_exec($curl);
        curl_close($curl);

        $info = $img->getInfo();

        finfo_close($finfo);

        return $info;
    }
699952
public function image($dir, $image, $width = null, $height = null, array $options = [], array $attributes = [])
    {
        $attributes = array_replace_recursive($this->attributes, $attributes);
        $options    = array_replace_recursive($this->options, $options);

        $path = config('laravelimage.routePath') . '/' . $dir . $image . '?' . http_build_query($options, '', '&');

        if ( ! empty((int) $width)) {
            $path .= '&w=' . (int) $width;
        }

        if ( ! empty((int) $height)) {
            $path .= '&h=' . (int) $height;
        }

        return '<img src="' . asset($path) . '" ' . $this->buildAttributes($attributes) . ' />';
    }
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);
        }
    }
1286696
public function addImageWatermark(Image $image, array $parameters): Image
    {
        $watermark = new Image($this->secret, $parameters['file'], null, $this->autorotate);

        // temporarily enable alphablending to be able to use 32-bit images
        imagealphablending($watermark->getData(), true);
        imagealphablending($image->getData(), true);

        // determine watermark position from config
        if (true === isset($parameters['position'])) {
            $top = intval($parameters['position']['top']) / 100;
            $left = intval($parameters['position']['left']) / 100;
        } else {
            $top = 1;
            $left = 1;
        }

        // determine watermark size from config
        if (true === isset($parameters['size'])) {
            if (self::WATERMARK_SIZE_COVER === $parameters['size']) {
                // cover dimensions are the same as crop dimensions
                $dimensions = $this->getAdjustedImageCropDimensions(
                    $watermark,
                    $image->getWidth(),
                    $image->getHeight(),
                    true
                );
                imagecopyresampled(
                    $image->getData(),
                    $watermark->getData(),
                    0,
                    0,
                    (int)(($watermark->getWidth() - $dimensions['width']) * $left),
                    (int)(($watermark->getHeight() - $dimensions['height']) * $top),
                    $image->getWidth(),
                    $image->getHeight(),
                    $dimensions['width'],
                    $dimensions['height']
                );
            } elseif (self::WATERMARK_SIZE_CONTAIN === $parameters['size']) {
                $dimensions = $this->getAdjustedImageDimensions($watermark, $image->getWidth(), $image->getHeight());
                imagecopyresampled(
                    $image->getData(),
                    $watermark->getData(),
                    (int)(($image->getWidth() - $dimensions['width']) * $left),
                    (int)(($image->getHeight() - $dimensions['height']) * $top),
                    0,
                    0,
                    $dimensions['width'],
                    $dimensions['height'],
                    $watermark->getWidth(),
                    $watermark->getHeight()
                );
            } else {		// percentage
                $dimensions = $this->getAdjustedImageDimensions($watermark, $image->getWidth(), $image->getHeight());
                $dimensions['width'] *= (intval($parameters['size']) / 100);
                $dimensions['height'] *= (intval($parameters['size']) / 100);
                imagecopyresampled(
                    $image->getData(),
                    $watermark->getData(),
                    (int)(($image->getWidth() - $dimensions['width']) * $left),
                    (int)(($image->getHeight() - $dimensions['height']) * $top),
                    0,
                    0,
                    $dimensions['width'],
                    $dimensions['height'],
                    $watermark->getWidth(),
                    $watermark->getHeight()
                );
            }
        } else {
            imagecopy(
                $image->getData(),
                $watermark->getData(),
                (int)(($image->getWidth() - $watermark->getWidth()) * $left),
                (int)(($image->getHeight() - $watermark->getHeight()) * $top),
                0,
                0,
                $watermark->getWidth(),
                $watermark->getHeight()
            );
        }

        // disable alphablending again to be able to save transparency
        imagealphablending($watermark->getData(), false);
        imagealphablending($image->getData(), false);

        return $image;
    }
903336
private static function resizeImage(array $src = [], array $dst = [], array $options = []): void
    {
        $srcImg = $src['function']($src['file']);
        $dstImg = \imagecreatetruecolor($dst['size']['w'], $dst['size']['h']);

        if (\in_array($src['type'], [IMAGETYPE_GIF, IMAGETYPE_PNG])) {
            $trIdx = \imagecolortransparent($srcImg);

            if ($trIdx > 0) {
                $trData = \imagecolorsforindex($srcImg, $trIdx);
                $background = \imagecolorallocate($dstImg, $trData['red'], $trData['green'], $trData['blue']);
                \imagefill($dstImg, 0, 0, $background);
                \imagecolortransparent($dstImg, $background);
            } elseif ($src['type'] == IMAGETYPE_PNG) {
                \imagealphablending($dstImg, false);
                $background = \imagecolorallocatealpha($dstImg, 0, 0, 0, 127);
                \imagefill($dstImg, 0, 0, $background);
                \imagesavealpha($dstImg, true);
            }
        }

        \imagecopyresampled(
            $dstImg,
            $srcImg,
            0,
            0,
            $dst['size']['src-box']['x'],
            $dst['size']['src-box']['y'],
            $dst['size']['w'],
            $dst['size']['h'],
            $dst['size']['src-box']['w'],
            $dst['size']['src-box']['h']
        );

        if ($options['gs'] === true) {
            \imagefilter($dstImg, IMG_FILTER_GRAYSCALE);
        }

        if (Directory::exists(\dirname($dst['file'])) === false) {
            Directory::create(\dirname($dst['file']));
        }

        $dst['function']($dstImg, $dst['file'], $dst['quality']);
    }
186450
function(image, options) {
        var imageKey = this.stampImage(image);
        var maskIndex = this._getImageMaskIndex(image, options);
        if (!maskIndex || !imageKey) {
            return this._buildImageMask(image, options);
        }
        var mask = maskIndex[imageKey];
        if (!mask) {
            mask = this._buildImageMask(image, options);
            maskIndex[imageKey] = mask;
        }
        return mask;
    }
637368
public function img($srcImagePath, $size = null, $options = []) {
        return Html::img(self::imgSrc($srcImagePath, $size), $options);
    }
1297310
def img2code(self, key, img):
        """"""

        code_template = \
            "wx.ImageFromData({width}, {height}, " + \
            "bz2.decompress(base64.b64decode('{data}'))).ConvertToBitmap()"

        code_alpha_template = \
            "wx.ImageFromDataWithAlpha({width}, {height}, " + \
            "bz2.decompress(base64.b64decode('{data}')), " + \
            "bz2.decompress(base64.b64decode('{alpha}'))).ConvertToBitmap()"

        data = base64.b64encode(bz2.compress(img.GetData(), 9))

        if img.HasAlpha():
            alpha = base64.b64encode(bz2.compress(img.GetAlphaData(), 9))
            code_str = code_alpha_template.format(
                width=img.GetWidth(), height=img.GetHeight(),
                data=data, alpha=alpha)
        else:
            code_str = code_template.format(width=img.GetWidth(),
                                            height=img.GetHeight(), data=data)

        return code_str
435667
public function image($image, $width=null, $height=null, $alt=null, $class=null, $link=null, $caption=null, $srcset=null) {
		$image = $this->getLink($image);
		$attributes = $this->getHtmlAttributes(array(
			'width'=>$width,
			'height'=>$height,
			'alt'=>$alt,
			'caption'=>$caption,
			'class'=>$class,
			'srcset'=>$srcset
		));

		$img = "<img src='$image'$attributes />";
		if (!is_null($link)) {
			$link = $this->getLink($link);
			return "<a href='$link'>$img</a>";
		}

		return $img;
	}