-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.min.js
1 lines (1 loc) · 1.88 KB
/
index.min.js
1
!function(){var e,t,a=document.querySelector(".width"),l=document.querySelector(".height"),n=document.querySelector(".result"),i=document.querySelector(".bgColor"),o=document.querySelector(".gen"),u=document.querySelector(".download"),s=document.querySelector(".block"),r=document.querySelector(".type_and_download_image"),c=document.querySelector("#imageType"),d=document.querySelector(".quality"),y=document.querySelector("#quality_value");c.addEventListener("input",function(){"png"===this.value?d.style.display="none":(t=s.toDataURL("image/jpeg"),d.style.display="block")}),y.addEventListener("input",function(){t="low"===this.value?s.toDataURL("image/jpeg",.1):"med"===this.value?s.toDataURL("image/jpeg",.6):s.toDataURL("image/jpeg",1)}),o.addEventListener("click",function(){""===a.value||a.value.match(/\s{1,}/)?(n.innerHTML="<span>Please insert width of the image.</span>",a.focus(),r.style.display="none"):isNaN(a.value)?(n.innerHTML=`<span>"${a.value}" is not a correct width value. Try - 45 / 50 / 85. kiddo!!</span>`,a.focus(),r.style.display="none"):""===l.value||l.value.match(/\s{1,}/)?(n.innerHTML="<span>Please insert height of the image.</span>",l.focus(),r.style.display="none"):isNaN(l.value)?(n.innerHTML=`<span>"${l.value}" is not a correct height value. Try - 45 / 50 / 85. kiddo!!</span>`,l.focus(),r.style.display="none"):(n.innerHTML="",s.style.display="block",s.setAttribute("width",parseInt(a.value)+"px"),s.setAttribute("height",parseInt(l.value)+"px"),(e=s.getContext("2d")).fillStyle=i.value,e.fillRect(0,0,a.value,l.value),e.font=a.value/15+"px Helvetica",e.fillStyle="#fff",e.textAlign="center",e.fillText(a.value+"px / "+l.value+"px",a.value/2,l.value/2),n.appendChild(s),r.style.display="block",t=s.toDataURL())}),u.addEventListener("click",function(){t?(this.setAttribute("href",t),this.setAttribute("download","new-generate-image-kiddo")):alert("Please choose a image format first.")})}();