const p=(o,m={})=>{const{maxWidth:s=1080,maxHeight:g=1080,quality:w=.85}=m;return new Promise((x,r)=>{const d=new FileReader;d.onload=u=>{var h;const e=new Image;e.onload=()=>{let t=e.width,n=e.height;if(t>s||n>g){const a=Math.min(s/t,g/n);t=Math.round(t*a),n=Math.round(n*a)}const i=document.createElement("canvas");i.width=t,i.height=n;const l=i.getContext("2d");if(!l){r(new Error("Cannot get canvas context"));return}l.drawImage(e,0,0,t,n),i.toBlob(a=>{if(!a){r(new Error("Canvas to Blob conversion failed"));return}const c=new File([a],o.name,{type:o.type||"image/jpeg",lastModified:Date.now()});console.log("Image resized:",{original:`${e.width}x${e.height} (${(o.size/1024).toFixed(2)} KB)`,resized:`${t}x${n} (${(c.size/1024).toFixed(2)} KB)`}),x(c)},o.type||"image/jpeg",w)},e.onerror=()=>{r(new Error("Image loading failed"))},e.src=(h=u.target)==null?void 0:h.result},d.onerror=()=>{r(new Error("File reading failed"))},d.readAsDataURL(o)})};export{p as resizeImage};
