Refactor image and mask utility functions

Moved convertToImage, createMaskFromImageSrc, and canvasToMaskImage from MaskProcessingUtils and mask_utils to ImageUtils for better modularity and reuse. Updated imports in dependent modules to use the new locations. Removed duplicate implementations from mask_utils and MaskProcessingUtils.
This commit is contained in:
Dariusz L
2025-07-27 18:47:41 +02:00
parent 9d0c946e22
commit 207bacc1f8
10 changed files with 113 additions and 95 deletions

View File

@@ -71,23 +71,6 @@ export async function processImageWithTransform(sourceImage, pixelTransform, opt
tempCtx.putImageData(imageData, 0, 0);
return tempCanvas;
}
/**
* Converts a canvas or image to an Image element
* @param source - Source canvas or image
* @returns Promise with Image element
*/
export async function convertToImage(source) {
if (source instanceof HTMLImageElement) {
return source; // Already an image
}
const image = new Image();
image.src = source.toDataURL();
await new Promise((resolve, reject) => {
image.onload = () => resolve();
image.onerror = reject;
});
return image;
}
/**
* Crops an image to a specific region
* @param sourceImage - Source image or canvas