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


TypeScript sharp.concurrency函数代码示例

本文整理汇总了TypeScript中sharp.concurrency函数的典型用法代码示例。如果您正苦于以下问题:TypeScript concurrency函数的具体用法?TypeScript concurrency怎么用?TypeScript concurrency使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了concurrency函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

    .resize(200, 200)
    .max()
    .toFormat('jpeg')
    .toBuffer()
    .then((outputBuffer: Buffer) => {
        // outputBuffer contains JPEG image data no wider than 200 pixels and no higher
        // than 200 pixels regardless of the inputBuffer image dimensions
    });

const stats = sharp.cache();

sharp.cache({ items: 200 });
sharp.cache({ files: 0 });
sharp.cache(false);

const threads = sharp.concurrency(); // 4
sharp.concurrency(2); // 2
sharp.concurrency(0); // 4

const counters = sharp.counters(); // { queue: 2, process: 4 }

let simd: boolean = sharp.simd();
// simd is `true` if SIMD is currently enabled

simd = sharp.simd(true);
// attempts to enable the use of SIMD, returning true if available

const vipsVersion: string = sharp.versions.vips;

if (sharp.versions.cairo) {
    const cairoVersion: string = sharp.versions.cairo;
开发者ID:minodisk,项目名称:DefinitelyTyped,代码行数:31,代码来源:sharp-tests.ts

示例2: require

const sharp = require("sharp")
sharp.concurrency(2)


const sizes: { [key: string]: { height: number, width: number} } = {
  large: { height: 1000, width: 1000 },
  medium: { height: 600, width: 600 },
  small: { height: 200, width: 200 },
  tiny: { height: 30, width: 30 },
}


/**
 * Create Image Output takes an image path, and returns an array of processed images
 * - large: full optimized image
 * - medium: Suitable for showing as article or gallery image
 * - small: Suitable for thumbnail, icon, etc
 * - tiny: Suitable only for progressive image loader
 * - svg-prog (SOONtm): SVG progressive image loader
 *  - https://jmperezperez.com/svg-placeholders/
 *  - https://github.com/fogleman/primitive
 *  - https://medium.com/front-end-hacking/progressive-image-loading-and-intersectionobserver-d0359b5d90cd
 */
export async function createImageOutput(sourcePath: string): Promise<any> {
  return Promise.all(Object.keys(sizes)
    .map(async (i: string) => sharp(sourcePath)
      .resize(sizes[i].width, sizes[i].height)
      .resize({ fit: "outside" })),
  )
}
开发者ID:Blanket-Warriors,项目名称:Blog-O-Matic,代码行数:30,代码来源:createImageOutput.ts


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