npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@qzsy/image-processing-sdk

v0.1.0

Published

TypeScript SDK for the Image Processing Service (subject cutout & icon slicing)

Readme

@qzsy/image-processing-sdk

Image Processing Service 的 TypeScript / Bun 客户端。

对接异步任务 API:创建主体抠图 / 图标切图任务 → 轮询状态 → 拿到 CDN 资源与 manifest。

  • 类型完整:请求、状态、manifest 均为严格类型,无 any
  • 运行时校验getJob / waitForJob 会对响应做结构收窄
  • 零依赖:使用标准 fetch(Bun / Node 18+ / 浏览器)

安装

在 monorepo 内本地引用:

cd sdk
bun install
bun run build

其他项目:

bun add ../path/to/image-processing-service/sdk
# 或 npm / pnpm / yarn 指向该目录

快速开始

import {
  ImageServiceClient,
  isSubjectManifest,
  isSliceSetManifest,
  ImageServiceJobError,
} from "@image-service/sdk";

const client = new ImageServiceClient({
  baseUrl: "http://localhost:8000",
  apiKey: process.env.IMAGE_SERVICE_API_KEY, // 服务端配置了 API_KEY 时必填
});

// 主体抠图:提交并等待完成
const subject = await client.subject({
  image_url: "https://cdn.example.com/product.jpg",
  remove_background: true,
  output: {
    canvas_width: 1024,
    canvas_height: 1024,
    format: "png",
  },
});

if (isSubjectManifest(subject.result)) {
  console.log(subject.result.asset.url);
  console.log(subject.result.processing.source_subject_box);
}

// 图标切图
const slices = await client.slices({
  image_url: "https://cdn.example.com/icon-sheet.png",
  options: {
    mode: "grid",
    rows: 3,
    columns: 3,
    background: "auto",
  },
});

if (isSliceSetManifest(slices.result)) {
  for (const item of slices.result.items) {
    console.log(item.name, item.asset.url);
  }
}

客户端配置

| 选项 | 类型 | 说明 | |------|------|------| | baseUrl | string | 服务地址,如 http://localhost:8000 | | apiKey? | string | 对应请求头 X-API-Key | | fetch? | typeof fetch | 自定义 fetch(测试 / 代理) | | headers? | Record<string, string> | 默认额外请求头 | | signal? | AbortSignal | 应用到单次 HTTP 请求 |

API 方法

健康检查

await client.live();  // GET /health/live  → { status: "ok" }
await client.ready(); // GET /health/ready → { status: "ready" }

创建任务(立即返回)

const created = await client.createSubjectJob({ image_url: "..." });
// { job_id, status: "queued", status_url }

const created2 = await client.createSliceJob({
  image_url: "...",
  options: { mode: "auto" },
});

查询 / 等待

const status = await client.getJob(created.job_id);
// status: "queued" | "running" | "succeeded" | "failed"

const done = await client.waitForJob(created.job_id, {
  intervalMs: 1000,
  timeoutMs: 120_000,
  onProgress: (s) => console.log(s.progress, s.stage),
});

便捷方法 client.subject() / client.slices() = 创建 + waitForJob

任务状态与结果

JobStatusstatus 字段区分:

| status | 含义 | 关键字段 | |--------|------|----------| | queued | 排队中 | progress, stage | | running | 处理中 | progress, stage | | succeeded | 成功 | result(manifest) | | failed | 失败 | errorcode / message / retryable) |

成功时 result 为判别联合:

  • type: "subject"SubjectManifest(含 asset
  • type: "slice-set"SliceSetManifest(含 items[]

类型守卫:

import { isSubjectManifest, isSliceSetManifest, isSucceededJobStatus } from "@image-service/sdk";

if (isSucceededJobStatus(status) && isSubjectManifest(status.result)) {
  status.result.asset.url; // string
}

请求字段摘要

SubjectRequest

| 字段 | 默认 | 说明 | |------|------|------| | image_url | 必填 | HTTP(S) 图片 URL | | remove_background | true | 是否抠图 | | model | null | rembg 模型覆盖 | | alpha_matting | null | alpha matting 覆盖 | | output | 1024×1024 / padding 0.06 | 画布与编码 | | client_reference | null | 业务侧关联 ID(≤128) |

SliceRequest.options

| 字段 | 默认 | 说明 | |------|------|------| | mode | "auto" | auto / grid / components | | rows / columns | null | 必须成对;mode=grid 时必填 | | background | "auto" | auto / alpha / color / ai | | max_items | 200 | 最大切图数 | | output | 512×512 / padding 0.08 | 每个图标的画布 |

错误处理

| 错误类 | 场景 | |--------|------| | ImageServiceApiError | HTTP 4xx/5xx、网络失败(含 statuscodedetail) | | ImageServiceJobError | 任务 failed(含 jobErrorretryable) | | ImageServiceTimeoutError | waitForJob 超时 | | ImageServiceAbortError | AbortSignal 取消 |

try {
  await client.subject({ image_url: "..." });
} catch (err) {
  if (err instanceof ImageServiceJobError) {
    console.error(err.code, err.retryable, err.message);
  } else if (err instanceof ImageServiceApiError) {
    console.error(err.status, err.code, err.message);
  } else {
    throw err;
  }
}

常见 API codeunauthorizedjob_not_foundqueue_unavailable
常见任务 codedownload_errorunsafe_sourceinvalid_imageempty_subjectslice_detection_errorstorage_error

开发

bun install
bun run typecheck
bun run build
bun test

构建产物在 dist/(ESM + .d.ts)。

与服务端对应关系

| SDK | HTTP | |-----|------| | createSubjectJob | POST /v1/jobs/subject → 202 | | createSliceJob | POST /v1/jobs/slices → 202 | | getJob | GET /v1/jobs/{job_id} | | live / ready | GET /health/live / ready |

服务端仓库:上级目录 image-processing-service(FastAPI + Celery)。