@plaiceholder/base64
Version:
Roll-you-own Base64 placeholders.
27 lines (24 loc) • 589 B
JavaScript
import sharp from 'sharp';
const getBase64 = async imageBuffer => new Promise((resolve, reject) => {
sharp(imageBuffer).normalise().modulate({
saturation: 1.2,
brightness: 1
}).removeAlpha().resize(10, 10, {
fit: "inside"
}).toBuffer({
resolveWithObject: true
}).then(({
data,
info
}) => {
const {
format
} = info;
const base64 = `data:image/${format};base64,${data.toString("base64")}`;
resolve(base64);
}).catch(err => {
if (err) return reject(err);
});
});
export { getBase64 };
//# sourceMappingURL=index.modern.js.map