@capacitor-community/image-to-text

中文文档
8.0.0发布于 2026/01/12Hippocratic License Version 2.0TypeScriptESM + CJS零依赖近 30 天下载 1.4万

Image to Text (OCR) Plugin for Capacitor

原始使用文档
文档目录15 节
  1. Image To Text
  2. Credits
  3. Installation
  4. Usage
  5. Example with Camera
  6. iOS Usage
  7. Android Usage
  8. Create Firebase Project and App
  9. Add Firebase SDK
  10. API Reference
  11. detectText(...)
  12. Interfaces
  13. Enums
  14. Compatibility
  15. License


Image To Text

@capacitor-community/image-to-text

Capacitor plugin for image to text processing using Apple's Vision Framework for iOS and MLKit's Vision Framework for Android..

Credits

This project was forked from the Cap ML plugin written by Vennela Kodali. It was refactored and converted to Capacitor 4.

  • For Capacitor 4 projects use v4.x
  • For Capacitor 5 projects use v5.x
  • For Capacitor 6 projects use v6.x

Installation

npm install @capacitor-community/image-to-text

Usage

There is one method detectText that takes a filename of an image and will return the text associated with it.

Add the following to your application:

import { Ocr, TextDetections } from '@capacitor-community/image-to-text';

...

const data: TextDetections = await Ocr.detectText({ filename: '[get-filename-of-image-jpg]' });
for (let detection of data.textDetections) {
    console.log(detection.text);
}

The above code will convert the image file and console.log the text found in it.

Example with Camera

You can use the @capacitor/camera plugin to take a photo and convert it to text:

import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
import { Ocr, TextDetections } from '@capacitor-community/image-to-text';

...

const photo = await Camera.getPhoto({
  quality: 90,
  allowEditing: true,
  resultType: CameraResultType.Uri,
  source: CameraSource.Camera,
});

const data: TextDetections = await Ocr.detectText({ filename: photo.path });

for (let detection of data.textDetections) {
  console.log(detection.text);
}

A full sample application can be found here.

video of scanning a card and it being converted to text

iOS Usage

No additional setup is required to use this plugin in a iOS Capacitor project.

Android Usage

Your project must include a google-services.json file stored in the Android project folder (usually android/app).

Create Firebase Project and App

  • Sign in to console.firebase.google.com
  • Click on Add Project and follow through the steps.
  • Click the Android icon to create an android app.
  • Enter the Package Name which must match your apps package name (You can find it in android/app/AndroidManifest.xml).
  • Click Register App
  • Download google-services.json and save into your project's android/app directory.

Add Firebase SDK

The sample project has this in place in its build.gradle (see here as a reference).

Note: Most starter Capacitor projects are preconfigured to load google-services.json.

API Reference

detectText(...)

detectText(options: DetectTextFileOptions | DetectTextBase64Options) => Promise<TextDetections>

Detect text in an image

ParamTypeDescription
optionsDetectTextFileOptions | DetectTextBase64OptionsOptions for text detection

Returns: Promise<TextDetections>


Interfaces

TextDetections

PropType
textDetectionsTextDetection[]

TextDetection

PropType
bottomLeft[number, number]
bottomRight[number, number]
topLeft[number, number]
topRight[number, number]
textstring

DetectTextFileOptions

PropType
filenamestring
orientationImageOrientation

DetectTextBase64Options

PropType
base64string
orientationImageOrientation

Enums

ImageOrientation

MembersValue
Up'UP'
Down'DOWN'
Left'LEFT'
Right'RIGHT'

Compatibility

Images are expected to be in portrait mode only, i.e. with text facing up. It will try to process even otherwise, but note that it might result in gibberish.

iOS and Android are supported. Web is not.

Featureiosandroid
ML FrameworkCoreML VisionFirebase MLKit
Text Detection with Still ImagesYesYes
Detects lines of textYesYes
Bounding Coordinates for TextYesYes
Image OrientationYes (Up, Left, Right, Down)Yes (Up, Left, Right, Down)
Skewed TextYesUnreliable
Rotated Text (<~ 45deg)YesYes (but with noise)
On-DeviceYesYes
SDK/ios Versionios 13.0 or newerTargets API level >= 16
Uses Gradle >= 4.1
com.android.tools.build:gradle >= v3.2.1
compileSdkVersion >= 28

License

Hippocratic License Version 2.0.

For more information, refer to LICENSE file

版本与发布记录

@capacitor-community/image-to-text 共发布 11 个版本,首次发布于 2023/02/24;过去 12 个月发布了 1 个版本。

版本发布日期距今
8.0.0latest2026/01/129 个月前
7.0.02025/02/171.7 年前
6.0.12024/04/172 年前
6.0.02024/04/162 年前
5.0.32023/10/303 年前
5.0.22023/09/083 年前

关于 @capacitor-community/image-to-text 的常见问题

@capacitor-community/image-to-text 是什么?

Image to Text (OCR) Plugin for Capacitor

如何安装 @capacitor-community/image-to-text?

在项目目录运行 npm install @capacitor-community/image-to-text,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capacitor-community/image-to-text 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capacitor-community/image-to-text 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capacitor-community/image-to-text 可以商用吗?

@capacitor-community/image-to-text 使用 Hippocratic License Version 2.0 许可。声明的许可为 Hippocratic License Version 2.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor-community/image-to-text 的下载量有多少?

根据 npm 官方下载统计,@capacitor-community/image-to-text 在 2026/10/09 – 2026/11/07 这 30 天内被下载 14,075 次,日均约 469 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capacitor-community/image-to-text 还在维护吗?

最新版本 8.0.0 发布于 2026/01/12(9 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 1 个;首次发布于 2023/02/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。