车牌 OCR.

@param      $image
@param bool $isUrl 图片是否为网络地址 url

@return mixed

@throws TencentAIException

@see https://ai.qq.com/doc/plateocr.shtml
553058
public function plate($image, bool $isUrl = false)
    {
        return $this->image(self::PLATE, $image, $isUrl);
    }
1299761
private function ordered( $image ) {

        // Localize vars
        $width = $image->getWidth();
        $height = $image->getHeight();

        $thresholdMap = array(
            array( 15, 135, 45, 165 ),
            array( 195, 75, 225, 105 ),
            array( 60, 180, 30, 150 ),
            array( 240, 120, 210, 90 )
        );

        // Loop using image1
        $pixelIterator = $image->getCore()->getPixelIterator();
        foreach ($pixelIterator as $y => $rows) { /* Loop through pixel rows */
            foreach ( $rows as $x => $px ) { /* Loop through the pixels in the row (columns) */
                /**
                 * @var $px \ImagickPixel */
                $rgba = $px->getColor();

                $gray = round($rgba['r'] * 0.3 + $rgba['g'] * 0.59 + $rgba['b'] * 0.11);

                $threshold = $thresholdMap[ $x % 4 ][ $y % 4 ];
                $oldPixel  = ( $gray + $threshold ) / 2;
                if ( $oldPixel <= 127 ) { // Determine if black or white. Also has the benefit of clipping excess value
                    $newPixel = 0;
                } else {
                    $newPixel = 255;
                }

                // Current pixel
                $px->setColor("rgb($newPixel,$newPixel,$newPixel)");

            }
            $pixelIterator->syncIterator(); /* Sync the iterator, this is important to do on each iteration */
        }

        $type = $image->getType();
        $file = $image->getImageFile();
        $image = $image->getCore();

        return new Image( $image, $file, $width, $height, $type ); // Create new image with updated core

    }
1294979
public function handwriting($image, bool $isUrl = false)
    {
        return $this->image(self::HAND_WRITING, $image, $isUrl);
    }
183746
public function execute($image)
    {
        $width = $this->argument(0)->type('digit')->required()->value();
        $height = $this->argument(1)->type('digit')->required()->value();
        $anchor = $this->argument(2)->value('center');
        $relative = $this->argument(3)->type('boolean')->value(false);
        $bgcolor = $this->argument(4)->value();

        $original_width = $image->getWidth();
        $original_height = $image->getHeight();

        // check of only width or height is set
        $width = is_null($width) ? $original_width : intval($width);
        $height = is_null($height) ? $original_height : intval($height);

        // check on relative width/height
        if ($relative) {
            $width = $original_width + $width;
            $height = $original_height + $height;
        }

        // check for negative width/height
        $width = ($width <= 0) ? $width + $original_width : $width;
        $height = ($height <= 0) ? $height + $original_height : $height;

        // create new canvas
        $canvas = $image->getDriver()->newImage($width, $height, $bgcolor);

        // set copy position
        $canvas_size = $canvas->getSize()->align($anchor);
        $image_size = $image->getSize()->align($anchor);
        $canvas_pos = $image_size->relativePosition($canvas_size);
        $image_pos = $canvas_size->relativePosition($image_size);

        if ($width <= $original_width) {
            $dst_x = 0;
            $src_x = $canvas_pos->x;
            $src_w = $canvas_size->width;
        } else {
            $dst_x = $image_pos->x;
            $src_x = 0;
            $src_w = $original_width;
        }

        if ($height <= $original_height) {
            $dst_y = 0;
            $src_y = $canvas_pos->y;
            $src_h = $canvas_size->height;
        } else {
            $dst_y = $image_pos->y;
            $src_y = 0;
            $src_h = $original_height;
        }

        // make image area transparent to keep transparency
        // even if background-color is set
        $transparent = imagecolorallocatealpha($canvas->getCore(), 255, 255, 255, 127);
        imagealphablending($canvas->getCore(), false); // do not blend / just overwrite
        imagefilledrectangle($canvas->getCore(), $dst_x, $dst_y, $dst_x + $src_w - 1, $dst_y + $src_h - 1, $transparent);

        // copy image into new canvas
        imagecopy($canvas->getCore(), $image->getCore(), $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);

        // set new core to canvas
        $image->setCore($canvas->getCore());

        return true;
    }
1114627
function image(url) {
  url = url.replace(/\??#.*$/, '');
  var inliner = this;
  this.emit('progress', 'get image ' + basename(url));
  return this.get(url, { encoding: 'binary' }).then(function then(res) {
    if (url.indexOf('data:') === 0) {
      return url;
    }

    debug('image loaded: %s', url);

    // if the url is SVG, let's compress and use the XML directly
    if (res.body && mime.lookup(url) === 'image/svg+xml' &&
      !inliner.options.nosvg) {
      return new Promise(function (resolve, reject) {
        svgo.optimize(res.body.toString(), function (result) {
          debug('optimising svg');
          if (result.error) {
            debug('errored', result.error);
            return reject(new Error(result.error));
          }
          // supposing/given:
          // - we are in a CSS single quoted string
          // - this css *may* be in a HTML file, in a <style>
          // - this css *may* be in a HTML file, in a double-quoted attribute
          // - the optimizer possibly replaced:
          //   - & by &amp;  <<< unhandled: add a &amp; in the svg text to test
          //   - ' by &apos;
          //   - " by &quot; (not around attributes)
          // Thus, we have to do a tricky escape pattern
          // ... we use % encoding for html level escape
          // ... we need to use proper \ escape for css level escape
          // ... (or we could have a ' in ' problem (nested sinle quotes))
          // ... so, before anything, we need to escape both \ and %
          var replacements = {
            '<': '%3C',  // html escape
            '"': '%22',  // html escape
            '&quot;': '%22',  // html escape
            '#': '%23',  // css url path escape
            '\n': '\\n', // css string escape
            '\'': '\\\'',// css string escape
            '&apos;': '\\\'',// css string escape
          };
          var body = result.data.replace(/\\/g, '\\').replace(/%/g, '%25')
                     .replace(/[<"#\n']|&quot;|&apos;/g, function (m) {
            return replacements[m];
          });
          resolve('data:image/svg+xml;utf8,' + body);
        });
      });
    }

    // otherwise we base64 encode the image
    return 'data:' + res.headers['content-type'] + ';base64,' +
            new Buffer(res.body, 'binary').toString('base64');

  }).catch(function errorHandle(error) {
    debug('image %s failed to load', url, error);
    throw error;
  });
}
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);
    }
773125
public function execute($image)
    {
        $width = $this->argument(0)->type('digit')->required()->value();
        $height = $this->argument(1)->type('digit')->required()->value();
        $anchor = $this->argument(2)->value('center');
        $relative = $this->argument(3)->type('boolean')->value(false);
        $bgcolor = $this->argument(4)->value();

        $original_width = $image->getWidth();
        $original_height = $image->getHeight();

        // check of only width or height is set
        $width = is_null($width) ? $original_width : intval($width);
        $height = is_null($height) ? $original_height : intval($height);

        // check on relative width/height
        if ($relative) {
            $width = $original_width + $width;
            $height = $original_height + $height;
        }

        // check for negative width/height
        $width = ($width <= 0) ? $width + $original_width : $width;
        $height = ($height <= 0) ? $height + $original_height : $height;

        // create new canvas
        $canvas = $image->getDriver()->newImage($width, $height, $bgcolor);

        // set copy position
        $canvas_size = $canvas->getSize()->align($anchor);
        $image_size = $image->getSize()->align($anchor);
        $canvas_pos = $image_size->relativePosition($canvas_size);
        $image_pos = $canvas_size->relativePosition($image_size);

        if ($width <= $original_width) {
            $dst_x = 0;
            $src_x = $canvas_pos->x;
            $src_w = $canvas_size->width;
        } else {
            $dst_x = $image_pos->x;
            $src_x = 0;
            $src_w = $original_width;
        }

        if ($height <= $original_height) {
            $dst_y = 0;
            $src_y = $canvas_pos->y;
            $src_h = $canvas_size->height;
        } else {
            $dst_y = $image_pos->y;
            $src_y = 0;
            $src_h = $original_height;
        }

        // make image area transparent to keep transparency
        // even if background-color is set
        $rect = new \ImagickDraw;
        $fill = $canvas->pickColor(0, 0, 'hex');
        $fill = $fill == '#ff0000' ? '#00ff00' : '#ff0000';
        $rect->setFillColor($fill);
        $rect->rectangle($dst_x, $dst_y, $dst_x + $src_w - 1, $dst_y + $src_h - 1);
        $canvas->getCore()->drawImage($rect);
        $canvas->getCore()->transparentPaintImage($fill, 0, 0, false);

        $canvas->getCore()->setImageColorspace($image->getCore()->getImageColorspace());

        // copy image into new canvas
        $image->getCore()->cropImage($src_w, $src_h, $src_x, $src_y);
        $canvas->getCore()->compositeImage($image->getCore(), \Imagick::COMPOSITE_DEFAULT, $dst_x, $dst_y);
        $canvas->getCore()->setImagePage(0,0,0,0);

        // set new core to canvas
        $image->setCore($canvas->getCore());

        return true;
    }
914111
public function execute($image)
    {
        $width = $this->argument(0)->type('digit')->required()->value();
        $height = $this->argument(1)->type('digit')->required()->value();
        $x = $this->argument(2)->type('digit')->value();
        $y = $this->argument(3)->type('digit')->value();

        if (is_null($width) || is_null($height)) {
            throw new \Intervention\Image\Exception\InvalidArgumentException(
                "Width and height of cutout needs to be defined."
            );
        }

        $cropped = new Size($width, $height);
        $position = new Point($x, $y);

        // align boxes
        if (is_null($x) && is_null($y)) {
            $position = $image->getSize()->align('center')->relativePosition($cropped->align('center'));
        }

        // crop image core
        return $this->modify($image, 0, 0, $position->x, $position->y, $cropped->width, $cropped->height, $cropped->width, $cropped->height);
    }
658743
function ParseUrl($url) {
	    $content = null;

    	$this->Clear();

		$this->url = htmlspecialchars_decode($url);

	    ob_start();
	    if (function_exists('curl_init')) {
		    //curl is the preferred function
		    $crl = curl_init();
		    curl_setopt($crl, CURLOPT_URL, $url);
		    curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
		    curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 5);
		    curl_setopt($crl, CURLOPT_TIMEOUT, 20);
		    $FileData = curl_exec($crl);
		    $FileInfo = curl_getinfo($crl);
		    curl_close($crl);
		    if ($FileInfo['http_code'] != 200) {
			    throw new \HttpRequestException($FileInfo['http_code'] . ' error for file: ' . $url);
		    }
	    } else {
		    //see if we can use fopen to get file
		    $fopen_check = ini_get('allow_url_fopen');
		    if (!empty($fopen_check)) {
			    $content = file_get_contents($url);
		    } else {
			    throw new \RuntimeException('CURL_DISABLED');
		    }
	    }
	    ob_end_clean();

		if(strlen($content)) {
			$this->modifyContent($content);
			$this->ParseStr($content);
			return true;
		} else {
			return false;
		}
	}
1029304
public function execute($image)
    {
        $width = $this->argument(0)->type('digit')->required()->value();
        $additionalConstraints = $this->argument(1)->type('closure')->value();

        $this->arguments[0] = $width;
        $this->arguments[1] = null;
        $this->arguments[2] = function ($constraint) use ($additionalConstraints) {
            $constraint->aspectRatio();
            if(is_callable($additionalConstraints))
                $additionalConstraints($constraint);
        };

        return parent::execute($image);
    }
1145698
public function createImageFromUrl($url)
    {
        $file = wei()->file->downloadOnDemand($url);
        $file = file_get_contents($file);

        return imagecreatefromstring($file);
    }
407532
public function getUrl($image, $imageQuery = NULL)
    {
        // Experimental support for absolute picture url when is relative generator url set
        if($imageQuery && Strings::startsWith($imageQuery, '//'))
        {
            $imageQuery = Strings::substring($imageQuery, 2);
            $imageUrl   = $this->getPictureGeneratorUrl($image, $imageQuery);

            if($this->isUrlRelative)
            {
                if($this->websiteUrl)
                {
                    return $this->websiteUrl . $imageUrl;
                }
                else
                {
                    return '//' . $_SERVER['SERVER_ADDR'] . $imageUrl;
                }
            }
            else
            {
                return $imageUrl;
            }
        }

        return $this->getPictureGeneratorUrl($image, $imageQuery);
    }
192822
public function run(Image $image)
    {
        if ($watermark = $this->getImage($image)) {
            $markw = $this->getDimension($image, 'markw');
            $markh = $this->getDimension($image, 'markh');
            $markx = $this->getDimension($image, 'markx');
            $marky = $this->getDimension($image, 'marky');
            $markpad = $this->getDimension($image, 'markpad');
            $markfit = $this->getFit();
            $markpos = $this->getPosition();
            $markalpha = $this->getAlpha();

            if ($markpad) {
                $markx = $marky = $markpad;
            }

            $size = new Size();
            $size->setParams([
                'w' => $markw,
                'h' => $markh,
                'fit' => $markfit,
            ]);
            $watermark = $size->run($watermark);

            if ($markalpha < 100) {
                $watermark->opacity($markalpha);
            }

            $image->insert($watermark, $markpos, intval($markx), intval($marky));
        }

        return $image;
    }
593155
public static function makeThumb($image, $thumbName, $type = null, $width = 100, $height = 50, $isAutoFix = true)
    {
        is_dir(dirname($thumbName)) || mkdir(dirname($thumbName), 0700, true);
        $imageInfo = self::getImageInfo($image);
        if (!$imageInfo) return false;

        $type = is_null($type) ? strtolower($imageInfo['ext']) : strtolower(($type == 'jpg' ? 'jpeg' : $type));

        if ($isAutoFix) { //根据比例缩放
            $fixScale = min($width  / $imageInfo['width'], $height / $imageInfo['height']);//缩放的比例
            if ($fixScale > 1) {
                //缩略图超过原图大小
                $width = $imageInfo['width'];
                $height = $imageInfo['height'];
            } else {
                $width = $imageInfo['width'] * $fixScale;
                $height = $imageInfo['height'] * $fixScale;
            }
        } else {
            ($width > $imageInfo['width']) && $width = $imageInfo['width'];
            ($height > $imageInfo['height']) && $height = $imageInfo['height'];
        }

        if (!in_array($type, ['jpeg', 'gif', 'png'])) {
            return false;
        }
        $createImageFunc = "imagecreatefrom{$type}";
        $sourceCreateImage = $createImageFunc($image);//载入原图

        //生成缩略图
        if ($type == 'gif' || !function_exists('imagecreatetruecolor')) {
            $thumbImg = imagecreate($width, $height);
        } else {
            $thumbImg = imagecreatetruecolor($width, $height);
        }

        if ($type == 'png') {
            imagealphablending($thumbImg, false);//取消默认的混色模式（为解决阴影为绿色的问题）
            imagesavealpha($thumbImg,true);//设定保存完整的 alpha 通道信息（为解决阴影为绿色的问题）
        } elseif ($type == 'gif') {
            $transparentIndex = imagecolortransparent($sourceCreateImage);
            if ($transparentIndex >= 0) {
                $transparentColor = imagecolorsforindex($sourceCreateImage , $transparentIndex);
                $transparentIndex = imagecolorallocate($thumbImg, $transparentColor['red'], $transparentColor['green'], $transparentColor['blue']);
                imagefill($thumbImg, 0, 0, $transparentIndex);
                imagecolortransparent($thumbImg, $transparentIndex);
            }
        }
        //复制
        function_exists('imagecopyresampled') ? imagecopyresampled($thumbImg, $sourceCreateImage, 0, 0, 0, 0, $width, $height, $imageInfo['width'], $imageInfo['height']) : imagecopyresized($thumbImg, $sourceCreateImage, 0, 0, 0, 0, $width, $height, $imageInfo['width'], $imageInfo['height']);
        self::output($thumbImg, $type, $thumbName);
        imagedestroy($sourceCreateImage);
        return $thumbName;
    }
809330
public function imageUrl($image)
    {
        if (!$image) {
            return '';
        }

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

        // deliver original file
        $src = $this->router->generate('frontendmedia_inline', ['fileId' => $fileId], UrlGeneratorInterface::ABSOLUTE_URL);

        return $src;
    }
1311013
public function execute($image)
    {
        $width = $this->argument(0)->type('digit')->required()->value();
        $height = $this->argument(1)->type('digit')->value($width);
        $constraints = $this->argument(2)->type('closure')->value();
        $position = $this->argument(3)->type('string')->value('center');

        // calculate size
        $cropped = $image->getSize()->fit(new Size($width, $height), $position);
        $resized = clone $cropped;
        $resized = $resized->resize($width, $height, $constraints);

        // crop image
        $image->getCore()->cropImage(
            $cropped->width,
            $cropped->height,
            $cropped->pivot->x,
            $cropped->pivot->y
        );

        // resize image
        $image->getCore()->scaleImage($resized->getWidth(), $resized->getHeight());
        $image->getCore()->setImagePage(0,0,0,0);

        return true;
    }
123383
public function qrcode($image, $options=array()){

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

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

        return $this->request($this->qrcodeUrl, $data);
    }