update at 2025-09-25 22:35:01

This commit is contained in:
douboer
2025-09-25 22:35:01 +08:00
parent a60cdd593c
commit c9ce811ce9
11 changed files with 1192 additions and 21 deletions

View File

@@ -25,6 +25,7 @@ import { Notice, TAbstractFile, TFile, Vault, MarkdownView, requestUrl, Platform
import { Extension } from "./extension";
import { NMPSettings } from "../settings";
import { IsImageLibReady, PrepareImageLib, WebpToJPG, UploadImageToWx } from "../imagelib";
import { convertJpegIfNeeded } from "../exif-orientation";
declare module 'obsidian' {
interface Vault {
@@ -87,6 +88,26 @@ export class LocalImageManager {
if (file == null) continue;
let fileData = await vault.readBinary(file);
let name = file.name;
// 处理 EXIF Orientation
try {
// 根据文件扩展名确定 MIME 类型
const mimeType = /\.jpe?g$/i.test(name) ? 'image/jpeg' :
/\.png$/i.test(name) ? 'image/png' :
/\.gif$/i.test(name) ? 'image/gif' :
/\.webp$/i.test(name) ? 'image/webp' : 'application/octet-stream';
const processed = await convertJpegIfNeeded(new Blob([fileData], { type: mimeType }), name);
if (processed.changed) {
fileData = await processed.blob.arrayBuffer();
name = processed.filename;
console.log(`[local-file] Applied orientation fix (${processed.orientation}) to ${name}`);
}
} catch (error) {
console.warn(`[local-file] EXIF orientation processing failed for ${name}:`, error);
// 继续使用原始文件
}
if (this.isWebp(file)) {
if (IsImageLibReady()) {
fileData = WebpToJPG(fileData);
@@ -199,6 +220,20 @@ export class LocalImageManager {
filename = 'remote_img' + this.getImageExtFromBlob(blob);
}
// 处理 EXIF Orientation
try {
const processed = await convertJpegIfNeeded(blob, filename);
if (processed.changed) {
data = await processed.blob.arrayBuffer();
filename = processed.filename;
blob = new Blob([data]);
console.log(`[local-file] Applied orientation fix (${processed.orientation}) to remote ${filename}`);
}
} catch (error) {
console.warn(`[local-file] EXIF orientation processing failed for remote ${filename}:`, error);
// 继续使用原始文件
}
if (this.isWebp(filename)) {
if (IsImageLibReady()) {
data = WebpToJPG(data);