format 格式

一个对象,它包含表示可用输入和输出格式/方法的嵌套布尔值。

例子

  1. console.log(sharp.format);

返回对象

interpolators 差值器

一个包含可用插值器及其正确值的对象。

类型:string

versions 版本

包含libvips版本号及其依赖项的Object。

例子

  1. console.log(sharp.versions);

vendor

一个对象,包含当前和已安装的供应商二进制文件的平台和体系结构。

例子

  1. console.log(sharp.vendor);

cache 缓存

获取或提供选项时,设置libvips的操作缓存的限制。限制发生任何更改后,缓存中的现有条目将被修剪。此方法始终返回高速缓存统计信息,这对于确定特定任务需要多少工作内存很有用。

参数

  • options Object | boolean 具有以下属性的对象,或者为boolean,其中true使用默认缓存设置,而false则删除所有缓存(可选,默认true
    • options.memory number 是用于此缓存的最大内存(以MB为单位50)(可选,默认)
    • options.files number 是要打开的最大文件数(可选,默认20
    • options.items number 是要缓存的最大操作数(可选,默认100

例子

  1. const stats = sharp.cache();
  1. sharp.cache( { items: 200 } );
  2. sharp.cache( { files: 0 } );
  3. sharp.cache(false);

返回对象

concurrency 并发

获取或提供并发时,设置libvips为处理每个图像而应创建的线程数。默认值为CPU内核数。值0将重置为该默认值。

libuv的UVTHREADPOOLSIZE环境变量限制了可以并行处理的最大图像数量。

此方法始终返回当前并发。

参数

  • concurrency number

例子

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

返回并发的number数

queue 队列

当任务为以下任一情况change时发出事件的EventEmitter :

  • queued,等待libuv提供工作线程
  • complete

例子

  1. sharp.queue.on('change', function(queueLength) {
  2. console.log('Queue contains ' + queueLength + ' task(s)');
  3. });

counters 计数器

提供对内部任务计数器的访问。

  • 队列是此模块已排队等待libuv从其池中提供工作线程的任务数。
  • process是当前正在处理的调整大小任务的数量。

例子

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

返回对象

simd

获取并设置SIMD向量单位指令的使用。需要libvips在liborc支持下进行编译。

改进的性能resizeblursharpen通过采取CPU的SIMD矢量单元,如英特尔SSE和ARM NEON的优势业务。

参数

  • simd boolean (可选,默认true

例子

  1. const simd = sharp.simd();
  2. // simd is `true` if the runtime use of liborc is currently enabled
  1. const simd = sharp.simd(false);
  2. // prevent libvips from using liborc at runtime

返回boolean