Decode image metadata in bounded workers and expose explicit ratio fitting

This commit is contained in:
2026-11-08 23:45:24 +08:00
parent 3ccb8dbc5c
commit 3750648dea
14 changed files with 129 additions and 19 deletions
+7
View File
@@ -0,0 +1,7 @@
const worker=globalThis as unknown as{onmessage:((event:MessageEvent)=>void)|null;postMessage(value:unknown):void};
worker.onmessage=async event=>{
const {version,id,bytes}=event.data??{};if(version!==1||!Number.isSafeInteger(id)||!(bytes instanceof Blob))return;
try{const bitmap=await createImageBitmap(bytes,{imageOrientation:'from-image'});let width:number,height:number;try{width=bitmap.width;height=bitmap.height;}finally{bitmap.close();}worker.postMessage({version:1,id,byteLength:bytes.size,width,height});}
catch{worker.postMessage({version:1,id,byteLength:bytes.size,error:'image_decode_failed'});}
};
export {};