refboard: export cropped images from visible frame
This commit is contained in:
@@ -12,6 +12,8 @@ import type { Viewport } from 'pixi-viewport';
|
|||||||
import type { Application } from 'pixi.js';
|
import type { Application } from 'pixi.js';
|
||||||
import type { SceneManager, SceneItem } from './SceneManager';
|
import type { SceneManager, SceneItem } from './SceneManager';
|
||||||
import { getItemWorldBounds } from './SceneManager';
|
import { getItemWorldBounds } from './SceneManager';
|
||||||
|
import { getImageVisibleLocalRect } from './imageTransforms';
|
||||||
|
import type { ImageObject } from './scene-format';
|
||||||
import { uploadImage } from '../api';
|
import { uploadImage } from '../api';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,8 +90,11 @@ export async function writeCanvasToClipboard(
|
|||||||
let maxRatio = 1;
|
let maxRatio = 1;
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const tex = (item.displayObject as any)?.texture;
|
const tex = (item.displayObject as any)?.texture;
|
||||||
if (tex && tex.width > 1 && item.data.w > 1) {
|
const displayW = item.type === 'image'
|
||||||
maxRatio = Math.max(maxRatio, tex.width / item.data.w);
|
? getImageVisibleLocalRect(item.data as ImageObject).w
|
||||||
|
: item.data.w;
|
||||||
|
if (tex && tex.width > 1 && displayW > 1) {
|
||||||
|
maxRatio = Math.max(maxRatio, tex.width / displayW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const resolution = Math.min(Math.max(maxRatio, window.devicePixelRatio || 1), 4);
|
const resolution = Math.min(Math.max(maxRatio, window.devicePixelRatio || 1), 4);
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import type { Viewport } from 'pixi-viewport';
|
|||||||
import type { Application } from 'pixi.js';
|
import type { Application } from 'pixi.js';
|
||||||
import type { SceneItem } from './SceneManager';
|
import type { SceneItem } from './SceneManager';
|
||||||
import { getItemWorldBounds } from './SceneManager';
|
import { getItemWorldBounds } from './SceneManager';
|
||||||
|
import { getImageVisibleLocalRect } from './imageTransforms';
|
||||||
|
import type { ImageObject } from './scene-format';
|
||||||
|
|
||||||
export interface ExportOptions {
|
export interface ExportOptions {
|
||||||
format: 'png' | 'jpeg' | 'webp';
|
format: 'png' | 'jpeg' | 'webp';
|
||||||
@@ -68,8 +70,11 @@ function renderToCanvas(
|
|||||||
let maxRatio = 1;
|
let maxRatio = 1;
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const tex = (item.displayObject as any)?.texture;
|
const tex = (item.displayObject as any)?.texture;
|
||||||
if (tex && tex.width > 1 && item.data.w > 1) {
|
const displayW = item.type === 'image'
|
||||||
maxRatio = Math.max(maxRatio, tex.width / item.data.w);
|
? getImageVisibleLocalRect(item.data as ImageObject).w
|
||||||
|
: item.data.w;
|
||||||
|
if (tex && tex.width > 1 && displayW > 1) {
|
||||||
|
maxRatio = Math.max(maxRatio, tex.width / displayW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const resolution = Math.min(maxRatio * scale, 8); // cap at 8x to avoid GPU limits
|
const resolution = Math.min(maxRatio * scale, 8); // cap at 8x to avoid GPU limits
|
||||||
@@ -176,8 +181,11 @@ export function getExportDimensions(
|
|||||||
let maxRatio = 1;
|
let maxRatio = 1;
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const tex = (item.displayObject as any)?.texture;
|
const tex = (item.displayObject as any)?.texture;
|
||||||
if (tex && tex.width > 1 && item.data.w > 1) {
|
const displayW = item.type === 'image'
|
||||||
maxRatio = Math.max(maxRatio, tex.width / item.data.w);
|
? getImageVisibleLocalRect(item.data as ImageObject).w
|
||||||
|
: item.data.w;
|
||||||
|
if (tex && tex.width > 1 && displayW > 1) {
|
||||||
|
maxRatio = Math.max(maxRatio, tex.width / displayW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const resolution = Math.min(maxRatio * scale, 8);
|
const resolution = Math.min(maxRatio * scale, 8);
|
||||||
|
|||||||
Reference in New Issue
Block a user