BỘ CÔNG CỤ TRỰC TUYẾN

Nén ảnh

Thao tác nhanh chóng, giao diện trực quan và dễ sử dụng trên mọi thiết bị.

Xử lý ngay trên thiết bị, không tải ảnh lên máy chủ. Hỗ trợ các định dạng trình duyệt đọc được.

');win.document.close();status.textContent='Chọn Lưu dưới dạng PDF trong hộp thoại in.';job?.success('Đã chuẩn bị ảnh để in PDF');return}const type=document.querySelector('#format').value,q=Number(document.querySelector('#quality').value);if(!(q>=0.1&&q<=1))throw Error('Chất lượng từ 0.1 đến 1');const blob=await new Promise((ok,fail)=>c.toBlob(b=>b?ok(b):fail(Error('Không xuất được ảnh')),type,q));const ext=blob.type==='image/png'?'png':blob.type==='image/webp'?'webp':'jpg';const u=URL.createObjectURL(blob);const save=document.querySelector('#save-image');if(window.s2ndImageUrl)URL.revokeObjectURL(window.s2ndImageUrl);window.s2ndImageUrl=u;save.href=u;save.download='s2nd-image.'+ext;save.hidden=false;const pv=document.querySelector('#preview');pv.src=u;pv.hidden=false;job?.success('Đã xử lý ảnh thành công');status.textContent='Đã xử lý: '+w+' × '+h+' px, '+(blob.size/1024).toFixed(1)+' KB. Bấm Tải ảnh ở bên dưới kết quả.'}catch(e){job?.error(e?.message||'Không thể xử lý ảnh');status.textContent=e.message}finally{btn.disabled=false;if(objectURL)URL.revokeObjectURL(objectURL)}};