修复2k尺寸解析导致图片缩成2像素
This commit is contained in:
parent
fc7e0316ee
commit
a921a9d984
@ -78,26 +78,38 @@ export function ImagePreview({
|
||||
let is4K = false;
|
||||
let parsed = false;
|
||||
|
||||
const applySizeInfo = (rawSize?: string) => {
|
||||
if (!rawSize) return;
|
||||
const normalized = rawSize.trim().toLowerCase();
|
||||
|
||||
if (normalized === "4k") {
|
||||
is4K = true;
|
||||
maxWidth = 500;
|
||||
return;
|
||||
}
|
||||
if (normalized === "2k") {
|
||||
is4K = false;
|
||||
maxWidth = 400;
|
||||
return;
|
||||
}
|
||||
if (normalized === "1k") {
|
||||
is4K = false;
|
||||
maxWidth = 300;
|
||||
return;
|
||||
}
|
||||
|
||||
// 仅纯数字时才按像素宽度解析,避免 "2k" 被 parseInt 误解析成 2
|
||||
if (/^\d+$/.test(normalized)) {
|
||||
maxWidth = parseInt(normalized, 10);
|
||||
}
|
||||
};
|
||||
|
||||
// 最新格式:使用 ||| 分隔 (不会与 LaTeX 数学公式或 Markdown 表格冲突)
|
||||
if (alt && alt.includes("thumb|||")) {
|
||||
const content = alt.substring(alt.indexOf("thumb|||") + 8);
|
||||
const parts = content.split("|||");
|
||||
originalUrl = parts[0];
|
||||
const extraInfo = parts[1];
|
||||
|
||||
if (extraInfo === "4K") {
|
||||
is4K = true;
|
||||
maxWidth = 500; // 4K 图片显示 500px 宽
|
||||
} else if (extraInfo === "2K") {
|
||||
// 2K 是高质量图片,显示较大尺寸
|
||||
is4K = false;
|
||||
maxWidth = 400; // 2K 图片显示 400px 宽
|
||||
} else if (extraInfo === "1K") {
|
||||
is4K = false;
|
||||
maxWidth = 300; // 1K 图片显示 300px 宽
|
||||
} else if (extraInfo && !isNaN(parseInt(extraInfo, 10))) {
|
||||
maxWidth = parseInt(extraInfo, 10);
|
||||
}
|
||||
applySizeInfo(parts[1]);
|
||||
parsed = true;
|
||||
console.log("[ImagePreview] Parsed with ||| format:", { originalUrl: originalUrl?.substring(0, 80), is4K });
|
||||
}
|
||||
@ -106,20 +118,7 @@ export function ImagePreview({
|
||||
const content = alt.substring(alt.indexOf("thumb$$") + 7);
|
||||
const parts = content.split("$$");
|
||||
originalUrl = parts[0];
|
||||
const extraInfo = parts[1];
|
||||
|
||||
if (extraInfo === "4K") {
|
||||
is4K = true;
|
||||
maxWidth = 500;
|
||||
} else if (extraInfo === "2K") {
|
||||
is4K = false;
|
||||
maxWidth = 400;
|
||||
} else if (extraInfo === "1K") {
|
||||
is4K = false;
|
||||
maxWidth = 300;
|
||||
} else if (extraInfo && !isNaN(parseInt(extraInfo, 10))) {
|
||||
maxWidth = parseInt(extraInfo, 10);
|
||||
}
|
||||
applySizeInfo(parts[1]);
|
||||
parsed = true;
|
||||
console.log("[ImagePreview] Parsed with $$ format:", { originalUrl: originalUrl?.substring(0, 80), is4K });
|
||||
}
|
||||
@ -128,20 +127,7 @@ export function ImagePreview({
|
||||
const content = alt.substring(alt.indexOf("thumb|") + 6);
|
||||
const parts = content.split("|");
|
||||
originalUrl = parts[0];
|
||||
const extraInfo = parts[1];
|
||||
|
||||
if (extraInfo === "4K") {
|
||||
is4K = true;
|
||||
maxWidth = 500;
|
||||
} else if (extraInfo === "2K") {
|
||||
is4K = false;
|
||||
maxWidth = 400;
|
||||
} else if (extraInfo === "1K") {
|
||||
is4K = false;
|
||||
maxWidth = 300;
|
||||
} else if (extraInfo && !isNaN(parseInt(extraInfo, 10))) {
|
||||
maxWidth = parseInt(extraInfo, 10);
|
||||
}
|
||||
applySizeInfo(parts[1]);
|
||||
parsed = true;
|
||||
console.log("[ImagePreview] Parsed with | format:", { originalUrl: originalUrl?.substring(0, 80), is4K });
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user