身份证识别.

@param string|\SplFileInfo $image 支持 JPG、PNG、BMP 格式
@param bool                $front 正面为 true

@throws TencentAIException

@return array

@see   https://ai.qq.com/doc/ocridcardocr.shtml
420433
public function idCard($image, bool $front = true)
    {
        $image = self::encode($image);

        $card_type = (int) !$front;

        return Request::exec(self::ID_CARD, compact('image', 'card_type'));
    }
535913
public function execute($image)
    {
        $filling = $this->argument(0)->value();
        $x = $this->argument(1)->type('digit')->value();
        $y = $this->argument(2)->type('digit')->value();

        $width = $image->getWidth();
        $height = $image->getHeight();
        $resource = $image->getCore();

        try {

            // set image tile filling
            $source = new Decoder;
            $tile = $source->init($filling);
            imagesettile($image->getCore(), $tile->getCore());
            $filling = IMG_COLOR_TILED;

        } catch (\Hail\Image\Exception\NotReadableException $e) {

            // set solid color filling
            $color = new Color($filling);
            $filling = $color->getInt();
        }

        imagealphablending($resource, true);

        if (is_int($x) && is_int($y)) {

            // resource should be visible through transparency
            $base = $image->getDriver()->newImage($width, $height)->getCore();
            imagecopy($base, $resource, 0, 0, 0, 0, $width, $height);

            // floodfill if exact position is defined
            imagefill($resource, $x, $y, $filling);

            // copy filled original over base
            imagecopy($base, $resource, 0, 0, 0, 0, $width, $height);

            // set base as new resource-core
            $image->setCore($base);
            imagedestroy($resource);

        } else {
            // fill whole image otherwise
            imagefilledrectangle($resource, 0, 0, $width - 1, $height - 1, $filling);
        }

        isset($tile) ? imagedestroy($tile->getCore()) : null;

        return true;
    }
741290
public function imageInspect($image)
    {
        return $this->browser->get(
            $this->uri->expand(
                '/images/{image}/json',
                array(
                    'image' => $image
                )
            )
        )->then(array($this->parser, 'expectJson'));
    }
365804
public function loadImage($image)
    {
        $imageLibrary = ucfirst($this->imageLibrary);
        $functionName = 'loadWith' . $imageLibrary;
        $this->image = $image;

        if (!method_exists($this, $functionName)) {
            throw new IcrRuntimeException('Wrong image library name provided!');
        }

        return call_user_func([$this, $functionName]);
    }
1373359
public function run(Image $image)
    {
        $width = $this->getWidth();
        $height = $this->getHeight();
        $fit = $this->getFit();
        $dpr = $this->getDpr();

        list($width, $height) = $this->resolveMissingDimensions($image, $width, $height);
        list($width, $height) = $this->applyDpr($width, $height, $dpr);
        list($width, $height) = $this->limitImageSize($width, $height);

        if ((int) $width !== (int) $image->width() or (int) $height !== (int) $image->height()) {
            $image = $this->runResize($image, $fit, (int) $width, (int) $height);
        }

        return $image;
    }
383990
public function runExpand(Image $image, $width, $color)
    {
        return $image->resizeCanvas(
            $width * 2,
            $width * 2,
            'center',
            true,
            $color
        );
    }
461624
private function distribute($image, Text $text) {

        if ( is_array($text->getContent()) ) {
            $textArray = array();
            foreach ($text->getContent() as $value) {
                $textArray[] = $this->getDiscreteText($value);
            }
            return $textArray;
        }

        $ttfBox = imagettfbbox($text->getFontsize(), $text->getAngle(), $text->getFont(), "我");
        $wordWidth = $ttfBox[2] - $ttfBox[0];  //文字宽度
        $wordHeight = abs($ttfBox[7]); //文字高度
        $imageSize = $this->getImageSize($image); //获取图片尺寸
        $textPool = $this->getDiscreteText($text->getContent()); //获取离散的文本
        $textWidth = $text->getMaxLineWidth(); //每行文本最大宽度
        if ( $textWidth == 0 ) {
            if ( $text->isVertical() ) {
                $textWidth = $imageSize[1]-$text->getStartY();
            } else {
                $textWidth = $imageSize[0]-$text->getStartX();
            }
        }
        if ( $text->isVertical() ) {
            $wordNumPerLine = floor($textWidth/$wordHeight); //每行字符数，垂直文本
        } else {
            $wordNumPerLine = floor($textWidth/$wordWidth); //每行字符数,水平文本
        }
        $textArray = array_chunk($textPool,$wordNumPerLine,false);

        return $textArray;
    }
1304364
private function getPathsForVolumeAsset($image)
    {
        try {
            $this->transformPath = ImagerHelpers::getTransformPathForAsset($image);
        } catch (InvalidConfigException $e) {
            Craft::error($e->getMessage(), __METHOD__);
            throw new ImagerException($e->getMessage(), $e->getCode(), $e);
        }

        $runtimeImagerPath = Craft::$app->getPath()->getRuntimePath().'/imager/';

        $this->url = $image->getUrl();
        $this->path = FileHelper::normalizePath($runtimeImagerPath.$this->transformPath.'/');
        $this->filename = $image->getFilename();
        $this->basename = $image->getFilename(false);
        $this->extension = $image->getExtension();

        try {
            FileHelper::createDirectory($this->path);
        } catch (Exception $e) {
            Craft::error($e->getMessage(), __METHOD__);
            throw new ImagerException($e->getMessage(), $e->getCode(), $e);
        }
    }
1008063
public function execute($image)
    {
        $level = $this->argument(0)->between(-100, 100)->required()->value();

        return imagefilter($image->getCore(), IMG_FILTER_CONTRAST, ($level * -1));
    }
983781
public function execute($image)
    {
        $amount = $this->argument(0)->between(0, 100)->value(10);

        // build matrix
        $min = $amount >= 10 ? $amount * -0.01 : 0;
        $max = $amount * -0.025;
        $abs = ((4 * $min + 4 * $max) * -1) + 1;
        $div = 1;

        $matrix = [
            [$min, $max, $min],
            [$max, $abs, $max],
            [$min, $max, $min]
        ];

        // apply the matrix
        return imageconvolution($image->getCore(), $matrix, $div, 0);
    }
85342
public static function getFromSpriteO( StaticImageDto $image, array $attributes = [] ): Html
	{
		return self::getFromSprite($image->sprite, $image->x, $image->y, $image->w, $image->h, $attributes);
	}
596863
public function run(Image $image)
    {
        if ($border = $this->getBorder($image)) {
            list($width, $color, $method) = $border;

            if ($method === 'overlay') {
                return $this->runOverlay($image, $width, $color);
            }

            if ($method === 'shrink') {
                return $this->runShrink($image, $width, $color);
            }

            if ($method === 'expand') {
                return $this->runExpand($image, $width, $color);
            }
        }

        return $image;
    }
770991
public function execute($image)
    {
        $mode = $this->argument(0)->type('bool')->value(true);

        imageinterlace($image->getCore(), $mode);

        return true;
    }
509314
public function apply( $image ) {

        imagefilter($image->getCore(), IMG_FILTER_PIXELATE, $this->amount, true);
        return $image;
    }
272202
public function execute($image)
    {
        if ($this->preferExtension && function_exists('exif_read_data')) {
            return parent::execute($image);
        }

        $core = $image->getCore();

        if ( ! method_exists($core, 'getImageProperties')) {
            throw new \Hail\Image\Exception\NotSupportedException(
                "Reading Exif data is not supported by this PHP installation."
            );
        }

        $requestedKey = $this->argument(0)->value();
        if ($requestedKey !== null) {
            $this->setOutput($core->getImageProperty('exif:' . $requestedKey));
            return true;
        }

        $exif = [];
        $properties = $core->getImageProperties();
        foreach ($properties as $key => $value) {
            if (substr($key, 0, 5) !== 'exif:') {
                continue;
            }

            $exif[substr($key, 5)] = $value;
        }

        $this->setOutput($exif);
        return true;
    }
1076660
public static function isImage($image)
	{
		if (!trim($image))
		{
			return false;
		}

		$dot = strrpos($image, '.') + 1;

		$ext = substr($image, $dot);
		$ext = strtolower($ext);
		if (!in_array($ext, array('gif', 'jpg', 'jpe', 'jpeg', 'png', 'bmp')))
		{
			return false;
		}

		return true;
	}
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);
    }