feat: relativize linked images

This commit is contained in:
Tomáš Mládek 2022-12-07 15:40:18 +01:00
parent 0f0afeae8d
commit b170941535

View file

@ -242,6 +242,11 @@
}); });
}); });
// Images
console.debug("[SVG] Processing images.");
const images = processImages(svg);
console.info(`[SVG] Found ${images.length} images.`);
// Audio areas // Audio areas
console.debug("[SVG] Processing audio areas."); console.debug("[SVG] Processing audio areas.");
audioAreas = processAudio(svg); audioAreas = processAudio(svg);
@ -386,6 +391,19 @@
return result; return result;
} }
function processImages(document: SVGElement): SVGImageElement[] {
const result: SVGImageElement[] = [];
Array.from(document.getElementsByTagName("image")).forEach((image) => {
console.debug(`[SVG/IMAGES] Found image #${image.id}.`);
const origPath = image.getAttribute("xlink:href").split("/");
let newHref = `content/images/${origPath[origPath.length - 1]}`;
newHref = newHref.replace(/jpg$/, "webp");
image.setAttribute("xlink:href", newHref);
result.push(image);
});
return result;
}
async function processScrolls( async function processScrolls(
svg: SVGElement, svg: SVGElement,
images: SVGImageElement[] images: SVGImageElement[]