- Implemented ComfyGenerateRequest type and associated functions for generating images using various architectures and modes. - Added functions for listing generation options and handling image uploads. - Created workflows for different generation modes including SDXL, Z-Image, Z-Image Turbo, and Anima. - Introduced GenerationJobStatus component to display the status of ongoing generation jobs. - Developed MaskControls for managing mask operations and displaying mask analysis. - Created palette items for tool selection, layer management, and generation settings.
25 lines
945 B
TypeScript
25 lines
945 B
TypeScript
export async function imageSourceToDataUrl(source: string): Promise<string> {
|
|
if (source.startsWith("data:")) return source;
|
|
const image = await loadImage(source);
|
|
const canvas = document.createElement("canvas");
|
|
canvas.width = image.naturalWidth;
|
|
canvas.height = image.naturalHeight;
|
|
const context = canvas.getContext("2d");
|
|
if (!context) throw new Error("Unable to read selected image");
|
|
context.drawImage(image, 0, 0);
|
|
return canvas.toDataURL("image/png");
|
|
}
|
|
|
|
export function loadImageSize(source: string): Promise<{ w: number; h: number }> {
|
|
return loadImage(source).then((image) => ({ w: image.naturalWidth, h: image.naturalHeight }));
|
|
}
|
|
|
|
function loadImage(source: string): Promise<HTMLImageElement> {
|
|
return new Promise((resolve, reject) => {
|
|
const image = new Image();
|
|
image.onload = () => resolve(image);
|
|
image.onerror = () => reject(new Error("Failed to load image"));
|
|
image.src = source;
|
|
});
|
|
}
|