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

text2media-sdk

v1.2.0

Published

AI图片生成任务SDK - 支持文生图、图生图、智能扩写、即梦4.0参考图

Downloads

31

Readme

text2media-sdk

AI图片生成任务SDK - 支持文生图、图生图、智能扩写

安装

npm install text2media-sdk

快速开始

1. 初始化SDK

import { initSdk } from 'text2media-sdk'

// 初始化SDK,配置API地址
initSdk({
  baseUrl: 'https://your-api-server.com',
  timeout: 30000, // 可选,默认30秒
  headers: {      // 可选,自定义请求头
    'Authorization': 'Bearer xxx'
  }
})

2. 使用组件(推荐)

<template>
  <ImgGenerator
    @success="handleSuccess"
    @error="handleError"
  />
</template>

<script setup>
import { ImgGenerator } from 'text2media-sdk'
import 'text2media-sdk/style.css'

const handleSuccess = (taskId) => {
  console.log('任务ID:', taskId)
  // 使用taskId查询任务结果
}

const handleError = (message) => {
  console.error('错误:', message)
}
</script>

3. 使用API

import { textToImg, imgToImg, textExpand, getTaskResult } from 'text2media-sdk'

// 文生图
const result = await textToImg({
  prompt: '一只可爱的猫咪',
  width: 1024,
  height: 1024,
  req_key: 'jimeng_t2i_v40', // 即梦4.0
}, 'jimeng')

console.log('任务ID:', result.data) // 44299

// 即梦 4.0 支持参考图(最多6张)
const resultWithRef = await textToImg({
  prompt: '一只可爱的猫咪',
  width: 2048,
  height: 2048,
  req_key: 'jimeng_t2i_v40',
  image_urls: [
    'https://xxx.com/ref-image-1.jpg',
    'https://xxx.com/ref-image-2.jpg',
  ]
}, 'jimeng')

// 查询任务结果
const taskResult = await getTaskResult(result.data)

// 图生图(风格转绘)
const imgResult = await imgToImg({
  image: 'https://xxx.com/image.jpg',
  control_type: 'Ghibli', // 吉卜力风格
})

// 智能扩写
const expandedText = await textExpand('一只猫', '2') // '2'表示图片扩写

API文档

initSdk(config)

初始化SDK配置

| 参数 | 类型 | 必填 | 说明 | |------|------|------|------| | baseUrl | string | 是 | API服务地址 | | timeout | number | 否 | 请求超时时间(ms),默认30000 | | headers | object | 否 | 自定义请求头 |

textToImg(params, vendor)

文生图

| 参数 | 类型 | 说明 | |------|------|------| | params.prompt | string | 提示词 | | params.width | number | 宽度 | | params.height | number | 高度 | | params.req_key | string | 模型标识 | | params.task_number | number | 生成数量 | | params.image_urls | string[] | 参考图URL(即梦4.0支持) | | vendor | string | API供应商:jimeng/qwen_img/lingxi |

返回: { code: 200, msg: '提交成功', data: 任务ID }

imgToImg(params)

图生图(风格转绘)

| 参数 | 类型 | 说明 | |------|------|------| | params.image | string | 原图URL | | params.control_type | string | 风格类型 | | params.direction | string | 文本方向描述(可选) |

textExpand(text, type)

智能扩写

| 参数 | 类型 | 说明 | |------|------|------| | text | string | 原始文本 | | type | '1' | '2' | 扩写类型:1-视频 2-图片 |

返回: 扩写后的文本

getTaskResult(taskId)

查询任务结果

| 参数 | 类型 | 说明 | |------|------|------| | taskId | number | 任务ID |

uploadImage(file)

上传图片

| 参数 | 类型 | 说明 | |------|------|------| | file | File | 图片文件 |

返回: 图片URL

组件文档

ImgGenerator

主组件,集成文生图和图生图功能

Props: 无

Events: | 事件 | 参数 | 说明 | |------|------|------| | success | taskId: number | 任务提交成功 | | error | message: string | 发生错误 |

Methods (通过ref调用):

  • getForm() - 获取表单数据
  • setForm(data) - 设置表单数据
  • generate() - 触发生成

功能特性:

  • 支持文生图和图生图两种模式
  • 即梦 4.0 模型支持上传参考图片(最多6张)
  • 内置智能扩写功能
  • 自动模型参数适配(尺寸、比例等)
  • 图片上传时自动验证尺寸和格式

ImgUpload

图片上传组件

Props: | 属性 | 类型 | 默认值 | 说明 | |------|------|--------|------| | modelValue | string | '' | 图片URL (v-model) | | label | string | '点击上传' | 上传提示文字 | | minWidth | number | 300 | 最小宽度(px) | | minHeight | number | 300 | 最小高度(px) | | maxSize | number | 10 | 最大文件大小(MB) |

Events: | 事件 | 参数 | 说明 | |------|------|------| | update:modelValue | url: string | 图片URL更新 | | success | url: string | 上传成功 | | error | message: string | 上传失败 |

PromptExpand

智能扩写组件

Props: | 属性 | 类型 | 默认值 | 说明 | |------|------|--------|------| | text | string | 必填 | 原始文本 | | type | '1' | '2' | '2' | 扩写类型 | | autoStart | boolean | true | 自动开始扩写 |

Events: | 事件 | 参数 | 说明 | |------|------|------| | use | result: string | 使用扩写结果 | | close | - | 关闭组件 |

模型支持

| 模型 | req_key | vendor | 尺寸范围 | 支持参考图 | |------|---------|--------|----------|-----------| | 即梦 4.0 | jimeng_t2i_v40 | jimeng | 1024-4096px | 是 | | 通用 3.0 | high_aes_general_v30l_zt2i | jimeng | 512-2048px | 否 | | 即梦 3.0 | jimeng_t2i_v30 | jimeng | 512-2048px | 否 | | 即梦 3.1 | jimeng_t2i_v31 | jimeng | 512-2048px | 否 | | 千问 3.0 | - | qwen_img | 512-2048px | 否 | | 灵犀 2.0 | - | lingxi | 1536x1536 | 否 |

风格类型

用于图生图的control_type参数:

  • Ghibli - 吉卜力
  • Anime - 漫画
  • Brushwork - 工笔
  • Ink - 水墨
  • Miniatur - 微缩景观
  • Watercolor - 水彩
  • Pencil - 铅笔素描
  • Americancomic - 美式漫画
  • 2-5D - 2.5D
  • 3D - 3D艺术
  • Chinesetrendy - 国潮
  • Texture - 肌理风

License

MIT