image-resolution-checker
Version:
A Vue 3 plugin for checking image resolutions with per - page settings
2 lines (1 loc) • 1.05 kB
JavaScript
(function(t,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(t=typeof globalThis<"u"?globalThis:t||self,i(t.ImageResolutionChecker={}))})(this,function(t){"use strict";const i=(e,a,l)=>new Promise((r,o)=>{const n=new FileReader;n.onload=h=>{var d;const s=new Image;s.onload=()=>{const g=s.width>=a,f=s.height>=l;r(g&&f)},s.onerror=()=>{o(new Error("Failed to load the image."))},s.src=(d=h.target)==null?void 0:d.result},n.onerror=()=>{o(new Error("Failed to read the image file."))},n.readAsDataURL(e)}),c=async(e,a,l)=>{if(!e)return[];const r=[];for(let o=0;o<e.length;o++)try{const n=await i(e[o],a,l);r.push({file:e[o],isValid:n})}catch(n){console.error(`Error checking resolution of file ${e[o].name}:`,n),r.push({file:e[o],isValid:!1})}return r},u={install:e=>{e.config.globalProperties.$checkImageResolutions=c}};t.checkImageResolutions=c,t.checkSingleImageResolution=i,t.default=u,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});