本文整理匯總了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;
示例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" })),
)
}