| Server IP : 185.208.173.17 / Your IP : 87.236.161.98 Web Server : Microsoft-IIS/10.0 System : Windows NT SRV8576125506 10.0 build 26100 (Windows Server 2016) AMD64 User : IUSR ( 0) PHP Version : 7.4.13 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/parsmega.nuxt/node_modules/@nuxt/image/dist/runtime/utils/ |
Upload File : |
export async function imageMeta(ctx, url) {
const cache = getCache(ctx);
const cacheKey = "image:meta:" + url;
if (cache.has(cacheKey)) {
return cache.get(cacheKey);
}
const meta = await _imageMeta(url).catch((err) => {
console.error("Failed to get image meta for " + url, err + "");
return {
width: 0,
height: 0,
ratio: 0
};
});
cache.set(cacheKey, meta);
return meta;
}
async function _imageMeta(url) {
if (process.server) {
const imageMeta2 = await import("image-meta").then((r) => r.default || r);
const data = await fetch(url).then((res) => res.buffer());
const metadata = imageMeta2(data);
if (!metadata) {
throw new Error(`No metadata could be extracted from the image \`${url}\`.`);
}
const {width, height} = metadata;
const meta = {
width,
height,
ratio: width && height ? width / height : void 0
};
return meta;
}
if (typeof Image === "undefined") {
throw new TypeError("Image not supported");
}
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = () => {
const meta = {
width: img.width,
height: img.height,
ratio: img.width / img.height
};
resolve(meta);
};
img.onerror = (err) => reject(err);
img.src = url;
});
}
function getCache(ctx) {
if (!ctx.nuxtContext.cache) {
if (ctx.nuxtContext.ssrContext && ctx.nuxtContext.ssrContext.cache) {
ctx.nuxtContext.cache = ctx.nuxtContext.ssrContext.cache;
} else {
const _cache = {};
ctx.nuxtContext.cache = {
get: (id) => _cache[id],
set: (id, value) => {
_cache[id] = value;
},
has: (id) => typeof _cache[id] !== "undefined"
};
}
}
return ctx.nuxtContext.cache;
}