Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add package.json and README.md file for npm package #50

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build:

.PHONY: clean
clean:
rm -rf dist/*
rm -rf js/dist/*
rm -rf target/

.PHONY: check
Expand Down Expand Up @@ -38,8 +38,8 @@ test-e2e:
.PHONY: wasm
wasm:
RUSTFLAGS="-C target-feature=+simd128" cargo build --release --target wasm32-unknown-unknown --package ocrs
wasm-bindgen target/wasm32-unknown-unknown/release/ocrs.wasm --out-dir dist/ --target web --reference-types --weak-refs
tools/optimize-wasm.sh dist/ocrs_bg.wasm
wasm-bindgen target/wasm32-unknown-unknown/release/ocrs.wasm --out-dir js/dist/ --target web --reference-types --weak-refs
tools/optimize-wasm.sh js/dist/ocrs_bg.wasm

.PHONY: wasm-all
wasm-all: wasm wasm-nosimd
9 changes: 9 additions & 0 deletions js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ocrs

Ocrs is a library for extracting text from images.

This is an alpha WebAssembly build of the library for use in Node, the browser
and other WebAssembly runtimes.

See the [Ocrs GitHub repository](https://github.com/robertknight/ocrs) for JS
examples and updates.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";

import { readFile } from "fs/promises";

import { program } from "commander";
Expand Down Expand Up @@ -84,10 +87,13 @@ program
.option("-j, --json", "Output JSON")
.action(
async (detectionModelPath, recognitionModelPath, imagePath, options) => {
const scriptDir = dirname(fileURLToPath(import.meta.url));
const wasmPath = `${scriptDir}/../../dist/ocrs_bg.wasm`;

// Concurrently load the OCR library, text detection and recognition models,
// and input image.
const [_, detectionModel, recognitionModel, image] = await Promise.all([
readFile("dist/ocrs_bg.wasm").then(initOcrLib),
readFile(wasmPath).then(initOcrLib),
readFile(detectionModelPath).then((data) => new Uint8Array(data)),
readFile(recognitionModelPath).then((data) => new Uint8Array(data)),
loadImage(imagePath),
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "ocrs",
"version": "0.1.0",
"description": "Ocrs is a library for extracting text from images",
"type": "module",
"main": "dist/ocrs.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"files": ["dist/**"],
"keywords": ["OCR"],
"author": "Robert Knight <[email protected]>",
"license": "MIT"
}
Loading