function i(o){return new Promise((r,n)=>{const e=new Image;e.onload=()=>r(e),e.onerror=()=>n(new Error("Could not decode image")),e.src=o})}function A(o){return new Promise((r,n)=>{const e=new FileReader;e.onload=()=>{typeof e.result=="string"?r(e.result):n(new Error("Could not read image"))},e.onerror=()=>n(new Error("Could not read image")),e.readAsDataURL(o)})}function l(o){return new Promise((r,n)=>{o.toBlob(e=>{e?r(e):n(new Error("Could not convert image to JPEG"))},"image/jpeg",.85)})}function u(o,r){if(o<=256&&r<=256)return{width:o,height:r};const n=Math.min(256/o,256/r);return{width:Math.max(1,Math.round(o*n)),height:Math.max(1,Math.round(r*n))}}async function d(o){const r=URL.createObjectURL(o);try{const n=await i(r),{width:e,height:a}=u(n.naturalWidth,n.naturalHeight),t=document.createElement("canvas");t.width=e,t.height=a;const c=t.getContext("2d");if(!c)throw new Error("Could not process image");c.drawImage(n,0,0,e,a);const s=await l(t);return A(s)}finally{URL.revokeObjectURL(r)}}export{d as p};
//# sourceMappingURL=avatar-image-DReUi3fE.js.map
