@hiddentao/clockwork-engine
Version:
A TypeScript/PIXI.js game engine for deterministic, replayable games with built-in rendering
18 lines (17 loc) • 526 B
JavaScript
const IMAGE_MIME_TYPES = {
png: "image/png",
jpg: "image/jpeg",
jpeg: "image/jpeg",
webp: "image/webp",
gif: "image/gif",
svg: "image/svg+xml",
};
/**
* Get the MIME type for an image based on file path extension.
* @param path - File path or filename with extension
* @returns MIME type string, defaults to 'image/png' for unknown extensions
*/
export function getImageMimeType(path) {
const ext = path.split(".").pop()?.toLowerCase() ?? "";
return IMAGE_MIME_TYPES[ext] ?? "image/png";
}