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);
|
||||
|
||||
// 优先保留原图,避免 base64 回退路径带来明显画质损失
|
||||
if (buffer.length <= 6 * 1024 * 1024) {
|
||||
return `data:${inputMime};base64,${buffer.toString("base64")}`;
|
||||
}
|
||||
|
||||
try {
|
||||
const sharp = await import("sharp");
|
||||
const optimized = await sharp.default(buffer)
|
||||
@ -61,7 +66,7 @@ async function fetchImageAsDataUri(url: string): Promise<string | null> {
|
||||
fit: "inside",
|
||||
withoutEnlargement: true,
|
||||
})
|
||||
.jpeg({ quality: 86, mozjpeg: true })
|
||||
.jpeg({ quality: 90, mozjpeg: true })
|
||||
.toBuffer();
|
||||
return `data:image/jpeg;base64,${optimized.toString("base64")}`;
|
||||
} catch {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user