修复了一点bug,然后增加了图层拆分更多的功能

This commit is contained in:
andy committed 2026-09-02 16:06:45 +08:00
1 parent 1305a9cdd8
commit ce8372e878
31 files changed
+2567 -391

No files matched your search

+18 -9
View File
@@ -2,6 +2,7 @@ export type SeedreamLayerCompositionItem = {
url: string;
visible: boolean;
box: [number, number, number, number];
rotation?: number;
};
export async function downloadSeedreamLayerComposition(options: {
@@ -14,7 +15,9 @@ export async function downloadSeedreamLayerComposition(options: {
const decoded: Array<{ item: SeedreamLayerCompositionItem; bitmap: ImageBitmap }> = [];
try {
for (const item of options.items) decoded.push({ item, bitmap: await fetchBitmap(item.url) });
for (const item of options.items) {
if (item.visible) decoded.push({ item, bitmap: await fetchBitmap(item.url) });
}
const reference = decoded[0].bitmap;
const width = positiveDimension(options.width) || reference.width;
const height = positiveDimension(options.height) || reference.height;
@@ -26,15 +29,21 @@ export async function downloadSeedreamLayerComposition(options: {
context.clearRect(0, 0, width, height);
for (const { item, bitmap } of decoded) {
if (!item.visible) continue;
const [left, top, right, bottom] = item.box;
context.drawImage(
bitmap,
left / 1000 * width,
top / 1000 * height,
Math.max(1, (right - left) / 1000 * width),
Math.max(1, (bottom - top) / 1000 * height)
);
const x = left / 1000 * width;
const y = top / 1000 * height;
const itemWidth = Math.max(1, (right - left) / 1000 * width);
const itemHeight = Math.max(1, (bottom - top) / 1000 * height);
const rotation = Number.isFinite(item.rotation) ? item.rotation || 0 : 0;
if (!rotation) {
context.drawImage(bitmap, x, y, itemWidth, itemHeight);
continue;
}
context.save();
context.translate(x + itemWidth / 2, y + itemHeight / 2);
context.rotate(rotation * Math.PI / 180);
context.drawImage(bitmap, -itemWidth / 2, -itemHeight / 2, itemWidth, itemHeight);
context.restore();
}
const blob = await canvasBlob(canvas, "image/png");