perf(volcano): preserve source quality for inline retry images
This commit is contained in:
parent
bfec61aad1
commit
cbad5ee2e2
@ -53,6 +53,11 @@ async function fetchImageAsDataUri(url: string): Promise<string | null> {
|
|||||||
|
|
||||||
const inputMime = response.headers.get("content-type") || guessImageMimeTypeFromUrl(url);
|
const inputMime = response.headers.get("content-type") || guessImageMimeTypeFromUrl(url);
|
||||||
|
|
||||||
|
// 优先保留原图,避免 base64 回退路径带来明显画质损失
|
||||||
|
if (buffer.length <= 6 * 1024 * 1024) {
|
||||||
|
return `data:${inputMime};base64,${buffer.toString("base64")}`;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const sharp = await import("sharp");
|
const sharp = await import("sharp");
|
||||||
const optimized = await sharp.default(buffer)
|
const optimized = await sharp.default(buffer)
|
||||||
@ -61,7 +66,7 @@ async function fetchImageAsDataUri(url: string): Promise<string | null> {
|
|||||||
fit: "inside",
|
fit: "inside",
|
||||||
withoutEnlargement: true,
|
withoutEnlargement: true,
|
||||||
})
|
})
|
||||||
.jpeg({ quality: 86, mozjpeg: true })
|
.jpeg({ quality: 90, mozjpeg: true })
|
||||||
.toBuffer();
|
.toBuffer();
|
||||||
return `data:image/jpeg;base64,${optimized.toString("base64")}`;
|
return `data:image/jpeg;base64,${optimized.toString("base64")}`;
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user