@talabes/football-lineup-generator
Version:
A TypeScript library for generating visual football lineup diagrams from team positioning data. Fork of ncamaa/football-lineup-generator with bug fixes and improvements.
23 lines (22 loc) • 725 B
JavaScript
export async function loadBackgroundImage(backgroundImage) {
if (!backgroundImage)
return null;
if (typeof backgroundImage === 'string') {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => {
resolve(img);
};
img.onerror = () => {
console.warn('Failed to load background image:', backgroundImage);
reject();
};
img.crossOrigin = 'anonymous'; // Enable CORS for external images
img.src = backgroundImage;
});
}
if (backgroundImage instanceof HTMLImageElement) {
return backgroundImage;
}
return null;
}