当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript image-size类代码示例

本文整理汇总了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));
  });
});
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:26,代码来源:image-size-tests.ts

示例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
				}
			};
开发者ID:Chan-PH,项目名称:vscode,代码行数:10,代码来源:imageSizeHelper.ts

示例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++;
  }
}
开发者ID:Deathspike,项目名称:mangarack,代码行数:10,代码来源:download.ts

示例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));
			}
		});
	});
开发者ID:Chan-PH,项目名称:vscode,代码行数:21,代码来源:imageSizeHelper.ts

示例5:

 }).on("end", () => {
   const buffer = Buffer.concat(chunks);
   console.log(sizeOf(buffer));
 });
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:4,代码来源:image-size-tests.ts


注:本文中的image-size类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。