PageSourceSearch

https://conversiontab.com/build/assets/image-black-white-converter-page-Dkn6bsWX.js

js conversiontab.com collected 2026-09-24 10:07:34 UTC 4,563 bytes, 1 lines download raw bytes

1import{o as T,t as A,p as M,f as S,i as q,q as P,l as N}from"./mediaInputFromFilename-AaKRjYpC.js";import{c as W,e as z}from"./ctMediaProgressUi-wz6CtyvX.js";import{w as G,c as H}from"./fileDropzone-CA_uaFcV.js";import{f as D}from"./ctMediaConvertDownload-n0-64pPl.js";import{w as J,c as K}from"./ctPendingDownload-B21SXRKd.js";import"./transientNotice-Ds_di7lD.js";import"./ctFullscreenAd-CL-AA_Ul.js";import"./app-gOHIPY12.js";function I(c){const o=document.getElementById("ctImgBwToastBody"),r=document.getElementById("ctImgBwToast");if(!o||!r||typeof bootstrap>"u"){window.alert(c);return}o.textContent=c,bootstrap.Toast.getOrCreateInstance(r).show()}function U(c){const o=(c||"png").toLowerCase();return o==="jpg"||o==="jpeg"?"image/jpeg":`image/${o}`}async function Q(c,o){let r;try{r=await createImageBitmap(c)}catch{return null}try{const a=document.createElement("canvas");a.width=r.width,a.height=r.height;const d=a.getContext("2d");if(!d)return null;d.filter="grayscale(100%)",d.drawImage(r,0,0),d.filter="none";const y=U(o),m=y==="image/jpeg"||y==="image/webp"?.92:void 0,u=await new Promise((w,i)=>{a.toBlob(g=>{g?w(g):i(new Error("toBlob failed"))},y,m)});return URL.createObjectURL(u)}catch{return null}finally{try{r.close()}catch{}}}function ae(){const c=document.getElementById("ct-image-bw-root");if(!c)return;const o=(c.dataset.ctFormat||"png").toLowerCase(),r=o==="jpg"?"jpeg":o,a=document.getElementById("ctImgBwFile"),d=document.getElementById("ctImgBwDrop"),y=document.getElementById("ctImgBwDropCaption"),m=document.getElementById("ctImgBwPreview"),u=document.getElementById("ctImgBwPreviewPh"),w=document.getElementById("ctImgBwName"),i=document.getElementById("ctImgBwBtn"),g=document.getElementById("ctImgBwDownload"),b=document.getElementById("ctImgBwClr"),t=W({barId:"ctImgBwProgBar",labelId:"ctImgBwProgLabel",percentId:"ctImgBwProgPct"});if(!a||!w||!i||!b)return;const h=K();J(g,h),a.setAttribute("accept",T()),d&&G({input:a,drop:d,dragContainer:d.closest(".card-body"),captionEl:y});let s,p,B=null;const F=()=>{B&&(URL.revokeObjectURL(B),B=null),m&&(m.removeAttribute("src"),m.classList.add("d-none")),u==null||u.classList.remove("d-none")};async function j(){return s&&!s.loaded&&(s=null,p=null),s||(p||(t(8,P(0)),p=N({onProgress:n=>{const l=8+Math.round(n*27);t(l,P(n))}}).then(n=>(s=n,n)).catch(n=>{throw p=null,s=null,t.ui.hardReset("Ready to convert"),n})),p)}a.addEventListener("change",()=>{var l;const n=(l=a.files)==null?void 0:l[0];if(F(),!n){i.disabled=!0,b.disabled=!0,t.ui.hardReset("Ready to convert");return}B=URL.createObjectURL(n),m&&(m.src=B,m.classList.remove("d-none")),u==null||u.classList.add("d-none"),i.disabled=!1,b.disabled=!1}),b.addEventListener("click",()=>{A(s),s=null,p=null,h.clear(),h.syncDownloadButton(g),H(a),F(),i.disabled=!0,b.disabled=!0,w.value="black_white_image",t.ui.hardReset("Ready to convert")}),i.addEventListener("click",async()=>{var C,R,L;const n=(C=a.files)==null?void 0:C[0];if(!n)return;if(n.size>50*1024*1024){I("File exceeds 50 MB.");return}t.beginEncoding("Converting…"),await new Promise(e=>{requestAnimationFrame(()=>e(void 0))});let l=null;try{l=await Q(n,o)}catch{l=null}if(l){i.disabled=!0;try{t(88,"Saving…");const e=(w.value||"black_white_image").replace(/[^\w\-]+/g,"_");await D(h,g,{objectUrl:l,filename:`${e}.${o}`,progressUi:t.ui}),t.ui.setDone("Done — click Download")}catch(e){I(e instanceof Error?e.message:"Conversion failed."),t.ui.hardReset("Ready to convert")}finally{i.disabled=!((R=a.files)!=null&&R.length)}return}const x=M(n.name,r);let f;try{f=await j()}catch(e){I(e instanceof Error?e.message:"Could not load the converter."),t.ui.hardReset("Ready to convert");return}if(!f){I("Could not load the converter."),t.ui.hardReset("Ready to convert");return}i.disabled=!0;const v=`input.${x}`,E=`output.${r}`;try{t(38,"Reading file…"),await f.writeFile(v,await S(n)),await z(f,["-y","-i",v,"-vf","format=gray",E],{phaseLo:42,phaseHi:90,labelForPercent:O=>`Converting… ${O}%`,onProgress:t}),t(92,"Saving…");const e=await f.readFile(E),k=e.buffer?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,_=new Blob([k],{type:U(o)}),$=(w.value||"black_white_image").replace(/[^\w\-]+/g,"_");await D(h,g,{blob:_,filename:`${$}.${o}`,progressUi:t.ui});try{await f.deleteFile(v),await f.deleteFile(E)}catch{}t.ui.setDone("Done — click Download")}catch(e){q(e)||I(e instanceof Error?e.message:"Conversion failed."),t.ui.hardReset("Ready to convert")}finally{i.disabled=!((L=a.files)!=null&&L.length)}})}export{ae as initImageBlackWhiteConverterPage};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.