全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

nodejs处理图片的中间件node-images详解

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

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

var images = require("images");

images("input.jpg")           //Load image from file 
                    //加载图像文件
  .size(400)             //Geometric scaling the image to 400 pixels width
                    //等比缩放图像到400像素宽
  .draw(images("logo.png"), 10, 10)  //Drawn logo at coordinates (10,10)
                    //在(10,10)处绘制Logo
  .save("output.jpg", {        //Save the image to a file,whih quality 50
    quality : 50          //保存图片到文件,图片质量为50
  });

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,您可以这样开始:

/* Load and decode image from file */
/* 从指定文件加载并解码图像 */
images(file)

/* Create a new transparent image */
/* 创建一个指定宽高的透明图像 */
images(width, height)

/* Load and decode image from a buffer */
/* 从Buffer数据中解码图像 */
images(buffer[, start[, end]])

/* Copy from another image */
/* 从另一个图像中复制区域来创建图像 */
images(image[, x, y, width, height])

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的垃圾回收机制

https://github.com/zhangyuanwei/node-images

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


# nodejs  # 图片处理  # node  # images  # 中间件处理图片  # 前端需知nodejs express中间件使用及定义详解  # nodejs express实现中间件  # NodeJs Express中间件超详细讲解  # Nodejs中Express 常用中间件 body-parser 实现解析  # 深入理解nodejs中Express的中间件  # nodejs关于中间件解析  # 图像处理  # 加载  # 链式  # 创建一个  # 将会  # 您可以  # 抛出  # 大家多多  # 无需安装  # 并保存  # 充好  # 编解码  # 发布了  # strong  # ol  # Features  # chaining  # API  # output  # save 


相关文章: 如何快速搭建响应式可视化网站?  如何在服务器上配置二级域名建站?  网站制作公司排行榜,四大门户网站排名?  高防服务器租用如何选择配置与防御等级?  宝华建站服务条款解析:五站合一功能与SEO优化设置指南  金*站制作公司有哪些,金华教育集团官网?  网站设计制作企业有哪些,抖音官网主页怎么设置?  手机网站制作平台,手机靓号代理商怎么制作属于自己的手机靓号网站?  香港服务器网站生成指南:免费资源整合与高速稳定配置方案  个人网站制作流程图片大全,个人网站如何注销?  广州网站制作的公司,现在专门做网站的公司有没有哪几家是比较好的,性价比高,模板也多的?  建站之星Pro快速搭建教程:模板选择与功能配置指南  如何在建站宝盒中设置产品搜索功能?  建站之星2.7模板快速切换与批量管理功能操作指南  建站VPS推荐:2025年高性能服务器配置指南  怎么制作一个起泡网,水泡粪全漏粪育肥舍冬季氨气超过25ppm,可以有哪些措施降低舍内氨气水平?  深圳网站制作公司好吗,在深圳找工作哪个网站最好啊?  太平洋网站制作公司,网络用语太平洋是什么意思?  建站之星下载版如何获取与安装?  建站之星如何实现PC+手机+微信网站五合一建站?  免费制作海报的网站,哪位做平面的朋友告诉我用什么软件做海报比较好?ps还是cd还是ai这几个软件我都会些我是做网页的?  浙江网站制作公司有哪些,浙江栢塑信息技术有限公司定制网站做的怎么样?  如何选择网络建站服务器?高效建站必看指南  香港网站服务器数量如何影响SEO优化效果?  网站代码制作软件有哪些,如何生成自己网站的代码?  建站之星导航配置指南:自助建站与SEO优化全解析  如何在IIS中新建站点并解决端口绑定冲突?  如何通过服务器快速搭建网站?完整步骤解析  如何自定义建站之星网站的导航菜单样式?  制作网站哪家好,cc、.co、.cm哪个域名更适合做网站?  大型企业网站制作流程,做网站需要注册公司吗?  香港服务器网站卡顿?如何解决网络延迟与负载问题?  郑州企业网站制作公司,郑州招聘网站有哪些?  赚钱网站制作软件,建一个网站怎样才能赚钱?是如何盈利的?  如何快速搭建个人网站并优化SEO?  济南网站制作的价格,历城一职专官方网站?  建站主机是否等同于虚拟主机?  宝塔Windows建站如何避免显示默认IIS页面?  网站制作员失业,怎样查看自己网站的注册者?  企业在线网站设计制作流程,想建设一个属于自己的企业网站,该如何去做?  建站之星展会模板:智能建站与自助搭建高效解决方案  香港服务器建站指南:外贸独立站搭建与跨境电商配置流程  佛山企业网站制作公司有哪些,沟通100网上服务官网?  盘锦网站制作公司,盘锦大洼有多少5G网站?  已有域名和空间如何搭建网站?  如何构建满足综合性能需求的优质建站方案?  php json中文编码为null的解决办法  详解jQuery中基本的动画方法  如何确保西部建站助手FTP传输的安全性?  建站主机如何选?性能与价格怎样平衡? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。