本文整理汇总了TypeScript中image-size类的典型用法代码示例。如果您正苦于以下问题:TypeScript image-size类的具体用法?TypeScript image-size怎么用?TypeScript image-size使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了image-size类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: sizeOf
import * as url from "url";
import * as http from "http";
import * as sizeOf from "image-size";
// Synchronous
const dimensions = sizeOf("images/funny-cats.png");
console.log(dimensions.width, dimensions.height);
// Asynchronous
sizeOf("images/funny-cats.png", (err, dimensions) => {
console.log(dimensions.width, dimensions.height);
});
// From URL
const imgUrl = "http://my-amazing-website.com/image.jpeg";
const options = url.parse(imgUrl);
http.get(options, (response) => {
const chunks: Buffer[] = [];
response.on("data", (chunk: Buffer) => {
chunks.push(chunk);
}).on("end", () => {
const buffer = Buffer.concat(chunks);
console.log(sizeOf(buffer));
});
});
示例2: sizeOf
const trySize = chunks => {
try {
const size = sizeOf(Buffer.concat(chunks, bufSize));
resp.removeListener('data', onData);
resp.destroy(); // no need to read further
resolve(sizeForFileName(path.basename(url.pathname), size));
} catch (err) {
// might not have enough data, skip error
}
};
示例3: archiveAsync
async function archiveAsync(chapter: archiver.Archiver, iterator: mio.IScraperIterator) {
let currentPageNumber = 1;
while (await iterator.moveAsync()) {
let buffer = await iterator.currentAsync();
let imageInfo = imageSize(buffer);
let name = `${String(currentPageNumber).padStart(3, '0')}.${imageInfo.type}`;
chapter.append(buffer, {name});
currentPageNumber++;
}
}
示例4: Promise
return new Promise((resolve, reject) => {
const isDataUrl = file.match(/^data:.+?;base64,/);
if (isDataUrl) {
// NB should use sync version of `sizeOf()` for buffers
try {
const data = Buffer.from(file.slice(isDataUrl[0].length), 'base64');
return resolve(sizeForFileName('', sizeOf(data)));
} catch (err) {
return reject(err);
}
}
sizeOf(file, (err, size) => {
if (err) {
reject(err);
} else {
resolve(sizeForFileName(path.basename(file), size));
}
});
});
示例5:
}).on("end", () => {
const buffer = Buffer.concat(chunks);
console.log(sizeOf(buffer));
});