Skip to content

Commit e9b1a68

Browse files
committed
Clone image before running lqip op
1 parent 8f41fce commit e9b1a68

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/lib/vite.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ function run(cfg) {
66
const lqip = (cfg && parseInt(cfg)) ?? 16
77
if (lqip) {
88
const { image } = metadatas.find((i) => i.src === pic.img.src)
9-
let data
109
if (lqip > 1) {
11-
const buf = await image.resize({ width: lqip }).toFormat('webp', { quality: 20 }).toBuffer()
12-
data = buf.toString('base64')
10+
const buf = await image
11+
.clone()
12+
.resize({ width: lqip })
13+
.toFormat('webp', { quality: 20 })
14+
.toBuffer()
15+
pic.img.lqip = buf.toString('base64')
1316
} else {
1417
const { dominant } = await image.stats()
1518
const { r, g, b } = dominant
16-
data = '#' + ((1 << 24) | (r << 16) | (g << 8) | b).toString(16).slice(1)
19+
pic.img.lqip = '#' + ((1 << 24) | (r << 16) | (g << 8) | b).toString(16).slice(1)
1720
}
18-
pic.img.lqip = data
1921
}
2022
return pic
2123
}

0 commit comments

Comments
 (0)