feat(images): 插件侧图片策略 v2 —— 全部改走宿主小图(album/promptlib/batch-export/annotate/vectorize/white-bg/cutout)
validate / validate (push) Canceled after 0s
validate / validate (push) Canceled after 0s
This commit is contained in:
1 parent
70613a4112
commit
9ceaa7d699
15 files changed
+53
-24
No files matched your search
@@ -369,7 +369,7 @@
|
|||||||
var sel = selectedNode()
|
var sel = selectedNode()
|
||||||
if (!sel) { warn('请先在画布选中一个节点'); return }
|
if (!sel) { warn('请先在画布选中一个节点'); return }
|
||||||
var img = null
|
var img = null
|
||||||
try { img = await ctx.canvas.getNodeImage(sel.id) } catch (error) { img = null }
|
try { img = await ctx.canvas.getNodeImage(sel.id, { max: 2048 }) } catch (error) { img = null }
|
||||||
var imgUrl = img && (img.dataUrl || img.url)
|
var imgUrl = img && (img.dataUrl || img.url)
|
||||||
if (!imgUrl) { warn('选中的节点没有可发送的图片'); return }
|
if (!imgUrl) { warn('选中的节点没有可发送的图片'); return }
|
||||||
content = [
|
content = [
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/album",
|
"name": "@iwb-plugin/album",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.2.3",
|
"version": "1.2.4",
|
||||||
"description": "相册:一个节点装多张本地图(只引用不复制),宫格自适应分页,一图一任务 / 批量两种模式批量生图",
|
"description": "相册:一个节点装多张本地图(只引用不复制),宫格自适应分页,一图一任务 / 批量两种模式批量生图",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "album",
|
"id": "album",
|
||||||
|
|||||||
+20
-4
@@ -669,11 +669,23 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) { /* 没缓存就现做 */ }
|
} catch (e) { /* 没缓存就现做 */ }
|
||||||
let dataUrl = ''
|
// v1.2.4(图片策略 v2):先让**宿主原生**出 320 小图 —— 不再把整幅原图读成 dataURL
|
||||||
|
// 再在 webview 里 canvas 缩放(那是 WebKit 上每次 21MB 的整幅解码,一夹 100 张就是 GB 级)。
|
||||||
const src = it && it.src
|
const src = it && it.src
|
||||||
try {
|
try {
|
||||||
if (fileRefOf(src)) dataUrl = await ctx.images.dataUrl(src)
|
if (ctx.images && typeof ctx.images.thumb === 'function') {
|
||||||
else if (typeof src === 'string') dataUrl = src
|
const u = await ctx.images.thumb(src, { max: 320 })
|
||||||
|
if (u && typeof u === 'string' && u.length < 512 * 1024) {
|
||||||
|
st.thumbs.set(key, u)
|
||||||
|
if (st.forceThumbs) st.forceThumbs.delete(key)
|
||||||
|
// 不再往 plugin-data 另存一份:宿主已在 thumbs/ 里按 hash 落了 tier,重复存等于两份
|
||||||
|
return u
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) { /* 回退到本地缩放 */ }
|
||||||
|
let dataUrl = ''
|
||||||
|
try {
|
||||||
|
if (typeof src === 'string' && src.indexOf('data:') === 0) dataUrl = src
|
||||||
else dataUrl = await ctx.images.dataUrl(src)
|
else dataUrl = await ctx.images.dataUrl(src)
|
||||||
} catch (e) { dataUrl = '' }
|
} catch (e) { dataUrl = '' }
|
||||||
if (!dataUrl) return ''
|
if (!dataUrl) return ''
|
||||||
@@ -742,7 +754,11 @@
|
|||||||
const flight = pending.get(key)
|
const flight = pending.get(key)
|
||||||
if (flight) return flight
|
if (flight) return flight
|
||||||
if (!ctx.images || typeof ctx.images.dataUrl !== 'function') return Promise.resolve('')
|
if (!ctx.images || typeof ctx.images.dataUrl !== 'function') return Promise.resolve('')
|
||||||
const p = Promise.resolve(ctx.images.dataUrl(it && it.src)).then((u) => {
|
// v1.2.4:大图也只取 2048 长边的预览(原生缩放),避免整幅解码 4K 原图
|
||||||
|
const ask = (ctx.images && typeof ctx.images.preview === 'function')
|
||||||
|
? Promise.resolve(ctx.images.preview(it && it.src, { max: 2048 })).then((r) => (r && r.dataUrl) || '')
|
||||||
|
: Promise.resolve(ctx.images.dataUrl(it && it.src))
|
||||||
|
const p = ask.then((u) => {
|
||||||
pending.delete(key)
|
pending.delete(key)
|
||||||
if (!u) return ''
|
if (!u) return ''
|
||||||
cache.set(key, u)
|
cache.set(key, u)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/batch-export",
|
"name": "@iwb-plugin/batch-export",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.2.2",
|
"version": "1.2.3",
|
||||||
"description": "批量出图:资源中心面板里勾选 ref 节点,串行跑(可选本机抠图)→ 白底/透明合成 → 双版本编码 → 打包 ZIP 下载;行内可单张下载 JPG/PNG",
|
"description": "批量出图:资源中心面板里勾选 ref 节点,串行跑(可选本机抠图)→ 白底/透明合成 → 双版本编码 → 打包 ZIP 下载;行内可单张下载 JPG/PNG",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "batch-export",
|
"id": "batch-export",
|
||||||
|
|||||||
@@ -577,7 +577,7 @@
|
|||||||
|
|
||||||
async function makeSrcThumb(nodeId) {
|
async function makeSrcThumb(nodeId) {
|
||||||
if (!ctx.canvas || typeof ctx.canvas.getNodeImage !== 'function') return null
|
if (!ctx.canvas || typeof ctx.canvas.getNodeImage !== 'function') return null
|
||||||
var image = await ctx.canvas.getNodeImage(nodeId)
|
var image = await ctx.canvas.getNodeImage(nodeId, { max: 64 }) // v: 缩略预览只要 64px,别整幅解码
|
||||||
var src = image && (image.dataUrl || image.url)
|
var src = image && (image.dataUrl || image.url)
|
||||||
if (!src) return null
|
if (!src) return null
|
||||||
var img = await loadImageEl(src)
|
var img = await loadImageEl(src)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-annotate",
|
"name": "@iwb-plugin/image-annotate",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.20.8",
|
"version": "1.20.9",
|
||||||
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
"description": "IWB 插件:图片标注 / 修图(编辑器移植自 iwb-plaus 扩展,纯 Canvas 2D)",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-annotate",
|
"id": "image-annotate",
|
||||||
|
|||||||
@@ -9214,7 +9214,8 @@ var __IWB_ANNOTATE_MANIFEST__ = {
|
|||||||
if (!editor || typeof editor.open !== "function") {
|
if (!editor || typeof editor.open !== "function") {
|
||||||
return Promise.reject(new Error("标注编辑器未加载"));
|
return Promise.reject(new Error("标注编辑器未加载"));
|
||||||
}
|
}
|
||||||
return Promise.resolve(ctx.canvas.getNodeImage(id)).then(function(image) {
|
// v: 编辑器入口封顶 4096 长边(原生缩),避免 8K 原图整幅进 canvas
|
||||||
|
return Promise.resolve(ctx.canvas.getNodeImage(id, { max: 4096 })).then(function(image) {
|
||||||
if (!image || !image.dataUrl) {
|
if (!image || !image.dataUrl) {
|
||||||
throw new Error(image && image.url ? "该节点是远程图片,暂不支持标注(请先转存为本地位图)" : "该节点没有可编辑的图片");
|
throw new Error(image && image.url ? "该节点是远程图片,暂不支持标注(请先转存为本地位图)" : "该节点没有可编辑的图片");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/image-vectorize",
|
"name": "@iwb-plugin/image-vectorize",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.6.1",
|
"version": "0.6.2",
|
||||||
"description": "位图转矢量:potrace(纯 JS)单色/灰度描摹,输出 SVG 与 PNG 节点;对文字、logo、线稿保形好,不需要 wasm",
|
"description": "位图转矢量:potrace(纯 JS)单色/灰度描摹,输出 SVG 与 PNG 节点;对文字、logo、线稿保形好,不需要 wasm",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "image-vectorize",
|
"id": "image-vectorize",
|
||||||
|
|||||||
@@ -3691,7 +3691,7 @@ var __IWB_VECTORIZE_MANIFEST__ = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function resolveImage(nodeId) {
|
async function resolveImage(nodeId) {
|
||||||
const image = await ctx.canvas.getNodeImage(nodeId);
|
const image = await ctx.canvas.getNodeImage(nodeId, { max: 2048 }); // v: 预览/矢量化封顶 2048
|
||||||
if (!image) throw new Error("该节点没有可描摹的图片");
|
if (!image) throw new Error("该节点没有可描摹的图片");
|
||||||
if (image.dataUrl) return image.dataUrl;
|
if (image.dataUrl) return image.dataUrl;
|
||||||
if (!image.url) throw new Error("该节点没有可描摹的图片");
|
if (!image.url) throw new Error("该节点没有可描摹的图片");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/promptlib",
|
"name": "@iwb-plugin/promptlib",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.14.9",
|
"version": "1.14.10",
|
||||||
"description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供",
|
"description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "promptlib",
|
"id": "promptlib",
|
||||||
|
|||||||
+19
-7
@@ -607,13 +607,25 @@
|
|||||||
// dataURL → { img: 文件名 };失败原样返回(宁可留着内联 base64,也不丢封面)
|
// dataURL → { img: 文件名 };失败原样返回(宁可留着内联 base64,也不丢封面)
|
||||||
function ensureCoverFile (cover) {
|
function ensureCoverFile (cover) {
|
||||||
if (!FILEAPI || typeof cover !== 'string' || cover.indexOf('data:') !== 0) return Promise.resolve(cover)
|
if (!FILEAPI || typeof cover !== 'string' || cover.indexOf('data:') !== 0) return Promise.resolve(cover)
|
||||||
var name = coverFileName(cover)
|
// v: 封面入库前先在**原生侧**缩到 512 —— 大封面会永久占 plugin-data,
|
||||||
pendingCoverNames[name] = 1
|
// 而且每次显示都要整幅解码(WebKit 上 4K 封面 = 21MB/次)。
|
||||||
return Promise.resolve(FILEAPI.put(name, cover)).then(function (r) {
|
var prepped = Promise.resolve(cover)
|
||||||
if (r && r.ok) return { img: name }
|
try {
|
||||||
delete pendingCoverNames[name]
|
if (PLP_CTX && PLP_CTX.images && typeof PLP_CTX.images.preview === 'function') {
|
||||||
return cover
|
prepped = Promise.resolve(PLP_CTX.images.preview(cover, { max: 512 }))
|
||||||
}).catch(function () { delete pendingCoverNames[name]; return cover })
|
.then(function (r) { return (r && r.ok && r.dataUrl) ? r.dataUrl : cover })
|
||||||
|
.catch(function () { return cover })
|
||||||
|
}
|
||||||
|
} catch (e) { /* 退回未压缩 */ }
|
||||||
|
return prepped.then(function (small) {
|
||||||
|
var name = coverFileName(small)
|
||||||
|
pendingCoverNames[name] = 1
|
||||||
|
return Promise.resolve(FILEAPI.put(name, small)).then(function (r) {
|
||||||
|
if (r && r.ok) return { img: name }
|
||||||
|
delete pendingCoverNames[name]
|
||||||
|
return small
|
||||||
|
}).catch(function () { delete pendingCoverNames[name]; return small })
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// 回收未被任何词条引用的封面文件(判定在模块级 plpGcCoverFiles,设置页复用同一套)。
|
// 回收未被任何词条引用的封面文件(判定在模块级 plpGcCoverFiles,设置页复用同一套)。
|
||||||
// 返回 { removed, bytes, skipped }
|
// 返回 { removed, bytes, skipped }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/white-bg-800",
|
"name": "@iwb-plugin/white-bg-800",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"description": "白底图:把节点图等比缩放居中合成到正方形画布,按格式/质量/体积上限编码,输出 <name>_<size>x<size>.<ext>;可开双版本出透明 PNG + 白底 JPG",
|
"description": "白底图:把节点图等比缩放居中合成到正方形画布,按格式/质量/体积上限编码,输出 <name>_<size>x<size>.<ext>;可开双版本出透明 PNG + 白底 JPG",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "white-bg-800",
|
"id": "white-bg-800",
|
||||||
|
|||||||
@@ -166,7 +166,7 @@
|
|||||||
// 绝不对 data: URL 发网络请求 —— 宿主 CSP connect-src 不含 data:,必被拦(姊妹插件 image-annotate 踩过并修掉的坑)。
|
// 绝不对 data: URL 发网络请求 —— 宿主 CSP connect-src 不含 data:,必被拦(姊妹插件 image-annotate 踩过并修掉的坑)。
|
||||||
// 远程 url 才走 fetch,转成 blob: URL 再解码(blob: 同样不污染画布)。
|
// 远程 url 才走 fetch,转成 blob: URL 再解码(blob: 同样不污染画布)。
|
||||||
async function resolveImage(nodeId) {
|
async function resolveImage(nodeId) {
|
||||||
const image = await ctx.canvas.getNodeImage(nodeId)
|
const image = await ctx.canvas.getNodeImage(nodeId, { max: 2048 }) // v: 白底处理封顶 2048
|
||||||
if (!image) throw new Error(NO_IMAGE)
|
if (!image) throw new Error(NO_IMAGE)
|
||||||
|
|
||||||
if (image.dataUrl) return loadImage(image.dataUrl)
|
if (image.dataUrl) return loadImage(image.dataUrl)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@iwb-plugin/xianyi-cutout",
|
"name": "@iwb-plugin/xianyi-cutout",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"description": "鲜艺抠图:调用本机 30092 的 /rmbg 把节点图抠成透明底",
|
"description": "鲜艺抠图:调用本机 30092 的 /rmbg 把节点图抠成透明底",
|
||||||
"ibwPlugin": {
|
"ibwPlugin": {
|
||||||
"id": "xianyi-cutout",
|
"id": "xianyi-cutout",
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
},
|
},
|
||||||
}, function (ctx) {
|
}, function (ctx) {
|
||||||
async function cutoutOne(nodeId) {
|
async function cutoutOne(nodeId) {
|
||||||
const image = await ctx.canvas.getNodeImage(nodeId)
|
const image = await ctx.canvas.getNodeImage(nodeId, { max: 2048 }) // v: 抠图封顶 2048
|
||||||
if (!image || !image.dataUrl) throw new Error('该节点没有可编码的图片(请选中带图的参考图或输出节点)')
|
if (!image || !image.dataUrl) throw new Error('该节点没有可编码的图片(请选中带图的参考图或输出节点)')
|
||||||
|
|
||||||
const apiUrl = trimUrl(ctx.settings.get('apiUrl'))
|
const apiUrl = trimUrl(ctx.settings.get('apiUrl'))
|
||||||
|
|||||||
Reference in new issue
Block a user