blur placeholder on article images
This commit is contained in:
1 parent
df229b5e8c
commit
8260e3cf34
9 files changed
+1108
-81
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import sharp from "sharp"
|
||||
|
||||
export async function encodeImageToBlurhash(url: string) {
|
||||
const res = await fetch(url)
|
||||
if (!res.ok) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const data = await res.arrayBuffer()
|
||||
const buffer = Buffer.from(data)
|
||||
|
||||
const t = sharp(buffer)
|
||||
.raw()
|
||||
.resize(8, 8, { fit: "inside" })
|
||||
.toFormat('jpeg')
|
||||
|
||||
const { data: out, info } = await t.toBuffer({ resolveWithObject: true })
|
||||
|
||||
return `data:image/jpeg;base64,${out.toString('base64')}`
|
||||
}
|
||||
Reference in new issue
Block a user