feat(image): preserve transparency for alpha images end to end
Skip WebP re-encoding for PNG/AVIF/BMP uploads and any bitmap that actually contains alpha, tag transparency-capable canvas uploads with the transparent-image tone, and detect alpha in merged layers so the composed node keeps a transparent tone. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3095,6 +3095,7 @@ export function CanvasWorkspace({ projectId }: { projectId: string }) {
|
||||
const previewUrl = URL.createObjectURL(file);
|
||||
const dimensions = await readImageDimensions(file).catch(() => ({ width: 512, height: 512 }));
|
||||
const size = fitCanvasImageSize(dimensions.width, dimensions.height);
|
||||
const tone = imageMaySupportTransparency(file) ? "transparent-image" : "natural";
|
||||
preparedUploads.push({
|
||||
file,
|
||||
previewUrl,
|
||||
@@ -5095,6 +5096,23 @@ function isImageFile(file: File) {
|
||||
return file.type.startsWith("image/") || /\.(png|jpe?g|webp|gif|avif|svg)$/i.test(file.name);
|
||||
}
|
||||
|
||||
function imageMaySupportTransparency(file: File) {
|
||||
const type = file.type.toLowerCase();
|
||||
const name = file.name.toLowerCase();
|
||||
return (
|
||||
type.includes("png") ||
|
||||
type.includes("webp") ||
|
||||
type.includes("avif") ||
|
||||
type.includes("gif") ||
|
||||
type.includes("svg") ||
|
||||
name.endsWith(".png") ||
|
||||
name.endsWith(".webp") ||
|
||||
name.endsWith(".avif") ||
|
||||
name.endsWith(".gif") ||
|
||||
name.endsWith(".svg")
|
||||
);
|
||||
}
|
||||
|
||||
function dataTransferImageFiles(dataTransfer: DataTransfer, fallbackBaseName = "canvas-image") {
|
||||
const candidates = [
|
||||
...Array.from(dataTransfer.files),
|
||||
|
||||
Reference in New Issue
Block a user