Download the PHP package qwen/image-ocr without Composer

On this page you can find all versions of the php package qwen/image-ocr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package image-ocr

Qwen Image OCR

基于通义千问视觉大模型(qwen-vl-ocr)的图片文字识别与 JSON 结构化输出 PHP 库。

通过调用阿里云 DashScope API,将图片中的文字内容智能识别并自动解析为结构化 JSON 数据。内置 9 种中国常见证件/票据类型的专用识别模板,开箱即用。

特性

支持的证件类型

类型 类名 标识符 说明
车牌 VehicleLicense vehicle_license 车牌号码
身份证正面 FrontIdCard frontIdCard 姓名、性别、民族、出生日期、住址、身份证号
身份证背面 BackIdCard backIdCard 签发机关、有效期限
营业执照 BusinessLicense businessLicense 统一社会信用代码、企业名称、法人、经营范围等 14 个字段
车辆合格证 Certificate certificate 合格证编号、车架号、发动机号等 38 个字段
发票 CarInvoice carInvoice 发票代码、金额、购销双方信息、明细行等 27 个字段
行驶证正页 FrontLicense frontLicense 号牌号码、车辆类型、所有人、VIN 等 11 个字段
行驶证副页 BackLicense backLicense 核定载人数、总质量、外廓尺寸等 12 个字段
驾驶证正面 FrontDrivingLicense frontDrivingLicense 证号、姓名、准驾类型、有效期限等 11 个字段
驾驶证背面 BackDrivingLicense backDrivingLicense 姓名、档案编号、记录、证号

安装

阿里云 Qwen 模型计费价格

模型 类型 输入价格 输出价格
qwen-vl-ocr 视觉识别 · OCR 专项 ¥0.3 / 百万 token ¥0.5 / 百万 token
qwen-vl-plus 视觉理解 · 多模态增强 ¥0.8 / 百万 token ¥2.0 / 百万 token
qwen3.6-flash 视觉理解 · 多模态增强 ¥1.2 / 百万 token ¥7.2 / 百万 token

计费单位:元(CNY)/ 每百万 token

仅需 OCR 文字识别,降低成本,默认使用 qwen-vl-ocr 模型;存在手写识别可切换为 qwen-vl-plus

快速开始

1. 通用文字识别

使用默认 Prompt,识别图片中所有文字并输出结构化 JSON:

2. 自定义 Prompt 识别

传入自定义指令,控制模型的输出格式:

3. 按证件类型识别(推荐)

使用内置的证件类型模板,精准提取特定字段:

4. 使用 Base64 图片

支持 base64 data URI 格式的图片输入:

证件类型识别示例

以下示例展示了所有 9 种证件类型的调用方式:

API 文档

Client

客户端核心类,提供三种识别方法。

__construct($apiKeyOrConfig, array $options = [])

创建客户端实例。

参数:

recognize(string $imageUrl): OcrResult

通用文字识别,使用默认 Prompt 提取图片中所有文字并结构化输出。

参数: $imageUrl — 图片 URL 或 base64 data URI

recognizeWithPrompt(string $imageUrl, string $instruction): OcrResult

使用自定义 Prompt 识别图片。

参数:

recognizeAs(string $imageUrl, OcrTypeInterface $type): OcrResult

按业务类型识别图片,使用证件类型专属的 system/user Prompt。

参数:

setPromptBuilder(PromptBuilder $builder): self

替换默认 PromptBuilder,用于高级定制。

setHttpClient(HttpClient $client): self

替换默认 Guzzle HttpClient,用于测试或代理场景。

OcrResult

识别结果封装类。

方法 返回类型 说明
getData() array 获取解析后的结构化数组
getRawText() string 获取模型返回的原始文本(可能包含 Markdown 代码块)
getRawResponse() array 获取完整的 API 响应数组
toJson(int $flags) string 将结构化数据序列化为 JSON 字符串
get(string $key, $default) mixed 快捷访问结构化数据中的某个键

OcrTypeInterface

证件类型接口,所有证件类型对象必须实现。

方法 说明
getSystemPrompt() 返回系统提示词(role: system 消息内容)
getUserPrompt() 返回用户提示词(包含字段提取指令和 JSON 格式要求)
getTypeName() 返回证件类型标识符(camelCase)
processResult(array $data): array 对解析后的结构化数据做后处理(如清洗噪音字符)。默认实现直接返回原数据,可按需覆盖

自定义证件类型

实现 OcrTypeInterface 接口或继承 AbstractOcrType 抽象类,即可创建自定义证件类型:

异常处理

高级用法

自定义 PromptBuilder

使用 Config 对象

Docker 运行

项目提供了 docker-compose.yml,可快速搭建运行环境:

项目结构

系统要求

许可证

MIT License

相关链接


All versions of image-ocr with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
guzzlehttp/guzzle Version ^6.5|^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package qwen/image-ocr contains the following files

Loading the files please wait ...