Skip to content

Commit

Permalink
Fix LqipRenderer in lib
Browse files Browse the repository at this point in the history
  • Loading branch information
tylermercer committed Jan 23, 2025
1 parent d17134e commit d44c3d5
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions lib/lqip/LqipRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class LqipRenderer {

private async assetToBase64Webp(file: string) {

const base64Image = (await cache.getOrCreate(await generateCacheKey({ file }), async () => {
const base64Image = (await this.cache.getOrCreate(await generateCacheKey({ file }), async () => {
return Buffer.from((await sharp(file)
.resize(16)
.webp()
Expand All @@ -19,24 +19,24 @@ export default class LqipRenderer {

public async getLqipStyles(imagePath: string) {
const webpImage = await this.assetToBase64Webp(imagePath);
return `
color: transparent;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-image: url('data:image/svg+xml;charset=utf-8,\
<svg xmlns="http://www.w3.org/2000/svg">\
<filter id="b" color-interpolation-filters="sRGB">\
<feGaussianBlur stdDeviation="20"/>\
<feComponentTransfer>\
<feFuncA type="discrete" tableValues="1 1"/>\
</feComponentTransfer>\
</filter>\
<g filter="url(%23b)">\
<image width="100%" height="100%" preserveAspectRatio="xMidYMid slice" href="${webpImage}"/>\
</g>\
</svg>');
`;
}
return `
color: transparent;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-image: url('data:image/svg+xml;charset=utf-8,\
<svg xmlns="http://www.w3.org/2000/svg">\
<filter id="b" color-interpolation-filters="sRGB">\
<feGaussianBlur stdDeviation="20"/>\
<feComponentTransfer>\
<feFuncA type="discrete" tableValues="1 1"/>\
</feComponentTransfer>\
</filter>\
<g filter="url(%23b)">\
<image width="100%" height="100%" preserveAspectRatio="xMidYMid slice" href="${webpImage}"/>\
</g>\
</svg>');
`;
}
}

0 comments on commit d44c3d5

Please sign in to comment.