ExtractBase64Images(html) Last updated: 15. Oct 2024

API only function

This function extracts images encoded in base64 from an HTML string. It then converts these images to a more storage-efficient format by saving them separately as embedded files. The revised HTML string will reference these images using a Content ID (CID) mechanism, similar to how images are referenced in email attachments.

Parameters

Name Type Description
html string The HTML string that contains images encoded in base64 format, which are to be extracted.

Returns

An object containing details of the extracted images and the modified HTML code, which has updated image references using CIDs.

Example

Code example (JS)

JS is normal JavaScript either running in the browser or on the Docly™ server.
let html = "<html><body><h1>Sample Image</h1><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' alt='small image'/></body></html>";
let extract = docly.extractBase64Images(html);
return extract;