optically-size-images
Version:
Normalize the size of a group of images, optically, based on their aspect ratios
2 lines (1 loc) • 422 B
JavaScript
const n=t=>t.complete&&t.naturalWidth!==0&&t.naturalHeight!==0,o=t=>{const c=t.naturalWidth,a=t.naturalHeight/c;let s=1- -(Math.cos(Math.PI*a)-1)/2/2.06;return a>1.5&&(s=(1-Math.cos(a*Math.PI/1.75))/2),a>5&&(s=1),Math.round((s+Number.EPSILON)*100)/100},l=(t,c)=>{t.map(e=>{const a=()=>{const s=o(e);c&&c(e,s)};n(e)?a():e.addEventListener("load",a)})};export{o as calculateOpticalImageSize,l as default,n as imageIsReady};