Skip to content
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
13 changes: 3 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
{
"name": "img-processing-sdk",
"version": "1.3.0",
"version": "1.4.0",
"description": "SDK for image processing",
"keywords": [
"img processing",
"image processing",
"api",
"sdk"
],
"keywords": ["img processing", "image processing", "api", "sdk"],
"homepage": "https://img-processing.com",
"license": "MIT",
"main": "dist/index.js",
Expand All @@ -27,9 +22,7 @@
"type": "git",
"url": "git+https://github.com/img-processing/node-sdk.git"
},
"files": [
"dist"
],
"files": ["dist"],
"type": "module",
"devDependencies": {
"@biomejs/biome": "1.8.3",
Expand Down
39 changes: 36 additions & 3 deletions src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,24 @@ export class IMGProcessingClient {
);
}

/**
* Extracts the text from an image and returns its content in the `format` specified in the request.
*
* **Note:** This method is not available in test mode, since test watermarks prevent accurate text extraction. If you want to test the capabilities of this endpoint, please switch to live mode to use this feature, or contact support to temporarily upgrade your account.
*/
async extractFormattedText({
image_id,
format,
}: IMGProcessingClient.extractFormattedText.Params): Promise<IMGProcessingClient.extractFormattedText.Response> {
return this.request(() =>
this.client.post(`v1/images/${image_id}/extract-formatted-text`, {
json: {
format,
},
}),
);
}

/**
* Visualize an image using a pre-trained model and generate an answer based on the prompt.
* The prompt can be a question, statement, or any text that you want to ask about the image. The API will analyze the content of the image and generate a response based on the prompt
Expand Down Expand Up @@ -311,7 +329,7 @@ export class IMGProcessingClient {
negative_prompt,
name,
seed,
model
model,
}: IMGProcessingClient.imagine.Params): Promise<ImageObject> {
return this.imageRequest(() =>
this.client.post<ImageObject>("v1/images/imagine", {
Expand All @@ -320,7 +338,7 @@ export class IMGProcessingClient {
negative_prompt,
name,
seed,
model
model,
},
}),
);
Expand Down Expand Up @@ -622,7 +640,7 @@ export declare namespace IMGProcessingClient {
/** The seed to use for the generation. */
seed?: number;
/** The model to use for the generation. */
model?: "sdxl" | "flux"
model?: "sdxl" | "flux";
};
}

Expand Down Expand Up @@ -881,4 +899,19 @@ export declare namespace IMGProcessingClient {
lines: string[];
};
}

export namespace extractFormattedText {
export type Params = {
/** The ID of the image to extract text. */
image_id: ImageId;
/** The format of the text to extract. */
format?: "plain" | "markdown";
};
export type Response = {
/** The format of the response. Default is `plain`. */
format: "plain" | "markdown";
/** The content extracted from the image. */
content: string;
};
}
}
19 changes: 19 additions & 0 deletions src/image-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ export class ImageObject<
return await this.client.extractText({ image_id: this.id });
}

/**
* Extracts the text from the current image and returns its content in the `format` specified.
*
* **Note:** This method is not available in test mode, since test watermarks prevent accurate text extraction. If you want to test the capabilities of this endpoint, please switch to live mode to use this feature, or contact support to temporarily upgrade your account.
*/
async extractFormattedText({
format,
}: ImageObject.extractFormattedText.Params = {}): Promise<ImageObject.extractFormattedText.Response> {
return await this.client.extractFormattedText({
image_id: this.id,
format,
});
}

/**
* Visualize an image using a pre-trained model and generate an answer based on the prompt.
* The prompt can be a question, statement, or any text that you want to ask about the image. The API will analyze the content of the image and generate a response based on the prompt
Expand Down Expand Up @@ -404,4 +418,9 @@ export declare namespace ImageObject {
export namespace extractText {
export type Response = IMGProcessingClient.extractText.Response;
}
export namespace extractFormattedText {
export type Params =
WithoutImageId<IMGProcessingClient.extractFormattedText.Params>;
export type Response = IMGProcessingClient.extractFormattedText.Response;
}
}
27 changes: 27 additions & 0 deletions test/analysis/extract-formatted-text.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { beforeAll, describe, expect, test } from "vitest";
import {
IMGProcessingAPIError,
IMGProcessingClient,
type ImageObject,
} from "../../src/index.js";
import { getApiKey, getAsset } from "../test-helpers.js";

describe("extract formatted text", () => {
const client: IMGProcessingClient = new IMGProcessingClient({
apiKey: getApiKey(),
});
let uploadedImage: ImageObject;
beforeAll(async () => {
uploadedImage = await client.uploadImage({
image: getAsset("test_image_1.jpeg"),
name: "test_image",
});
});
test("should extract text from an image", async () => {
const response = await uploadedImage.extractFormattedText();
expect(response).toMatchObject({
format: "plain",
content: expect.any(String),
});
});
});
4 changes: 2 additions & 2 deletions test/analysis/extract-text.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
IMGProcessingClient,
type ImageObject,
} from "../../src/index.js";
import { getApiKey, getAsset } from '../test-helpers.js';
import { getApiKey, getAsset } from "../test-helpers.js";

describe("extract text", () => {
const client: IMGProcessingClient = new IMGProcessingClient({
Expand All @@ -22,4 +22,4 @@ describe("extract text", () => {
expect(lines).toBeDefined();
expect(lines).toEqual(expect.arrayContaining([expect.any(String)]));
});
});
});