最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

nodejs中设置图片的中间件实例教程

来源:懂视网 责编:小采 时间:2020-11-27 20:22:48
文档

nodejs中设置图片的中间件实例教程

nodejs中设置图片的中间件实例教程:这篇文章主要介绍了nodejs处理图片的中间件node-images详解,非常具有实用价值,需要的朋友可以参考下Cross-platform image decoder(png/jpeg/gif) and encoder(png/jpeg) for Node.jsnode.js轻量级跨平台图像编解码库var image
推荐度:
导读nodejs中设置图片的中间件实例教程:这篇文章主要介绍了nodejs处理图片的中间件node-images详解,非常具有实用价值,需要的朋友可以参考下Cross-platform image decoder(png/jpeg/gif) and encoder(png/jpeg) for Node.jsnode.js轻量级跨平台图像编解码库var image

这篇文章主要介绍了nodejs处理图片的中间件node-images详解,非常具有实用价值,需要的朋友可以参考下

Cross-platform image decoder(png/jpeg/gif) and encoder(png/jpeg) for Node.js

node.js轻量级跨平台图像编解码库

Features 功能特性

  1. Lightweight:no need to install any image processing library.

  2. 轻量级:无需安装任何图像处理库。

  3. Cross-platform: Released a compiled .node file on windows, just download and start.

  4. 跨平台:Windows下发布了编译好的.node文件,下载就能用。

  5. Easy-to-use: Provide jQuery-like chaining API.Simple and reliable!

  6. 方便用:jQuery风格的API,简单可依赖。

Installation 安装

$ npm install images

API 接口

node-images provide jQuery-like Chaining API,You can start the chain like this:

node-images 提供了类似jQuery的链式调用API,您可以这样开始:

images(file)

Load and decode image from file从指定文件加载并解码图像

images(width, height)

Create a new transparent image创建一个指定宽高的透明图像

images(buffer[, start[, end]])

Load and decode image from a buffer从Buffer数据中解码图像

images(image[, x, y, width, height])

Copy from another image从另一个图像中复制区域来创建图像

.fill(red, green, blue[, alpha])

eg:images(200, 100).fill(0xff, 0x00, 0x00, 0.5) Fill image with color以指定颜色填充图像

.draw(image, x, y)

Draw image on the current image position( x , y )在当前图像( x , y )上绘制 image 图像

.encode(type[, config])

eg:images("input.png").encode("jpg", {operation:50}) Encode image to buffer, config is image setting.

以指定格式编码当前图像到Buffer,config为图片设置,目前支持设置JPG图像质量

Return buffer

返回填充好的Buffer

Note:The operation will cut off the chain

注意:该操作将会切断调用链

See:.save(file[, type[, config]]) 参考:.save(file[, type[, config]])

.save(file[, type[, config]])

eg:images("input.png").encode("output.jpg", {operation:50}) Encoding and save the current image to a file, if the type is not specified, type well be automatically determined according to the file, config is image setting. eg: { operation:50 }
编码并保存当前图像到 file ,如果type未指定,则根据 file 自动判断文件类型,config为图片设置,目前支持设置JPG图像质量

.size([width[, height]])

Get size of the image or set the size of the image,if the height is not specified, then scaling based on the current width and height获取或者设置图像宽高,如果height未指定,则根据当前宽高等比缩放

.resize(width[, height])

Set the size of the image,if the height is not specified, then scaling based on the current width and height

设置图像宽高,如果height未指定,则根据当前宽高等比缩放, 默认采用 bicubic 算法。

.width([width])

Get width for the image or set width of the image获取或设置图像宽度

.height([height])

Get height for the image or set height of the image获取或设置图像高度

images.setLimit(width, height)

Set the limit size of each image 设置库处理图片的大小限制,设置后对所有新的操作生效(如果超限则抛出异常)

images.setGCThreshold(value)

Set the garbage collection threshold 设置图像处理库自动gc的阈值(当新增内存使用超过该阈值时,执行垃圾回收)

images.getUsedMemory()

Get used memory (in bytes)得到图像处理库占用的内存大小(单位为字节)

images.gc()

Forced call garbage collection 强制调用V8的垃圾回收机制

github.com/zhangyuanwei/node-images

【相关推荐】

1. 免费js在线视频教程

2. JavaScript中文参考手册

3. php.cn独孤九贱(3)-JavaScript视频教程

文档

nodejs中设置图片的中间件实例教程

nodejs中设置图片的中间件实例教程:这篇文章主要介绍了nodejs处理图片的中间件node-images详解,非常具有实用价值,需要的朋友可以参考下Cross-platform image decoder(png/jpeg/gif) and encoder(png/jpeg) for Node.jsnode.js轻量级跨平台图像编解码库var image
推荐度:
标签: 教程 js 图像
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top