国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

nodejs處理圖片的中間件node-images詳解

2019-11-19 16:38:13
字體:
來源:轉載
供稿:網友

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 封丘县| 墨江| 旺苍县| 和龙市| 凤山市| 枣强县| 阳曲县| 夹江县| 宝清县| 桂东县| 贡山| 甘孜县| 开鲁县| 双鸭山市| 新郑市| 涟源市| 罗山县| 泰州市| 定襄县| 墨竹工卡县| 渝北区| 东乡| 岑溪市| 南澳县| 云龙县| 建湖县| 紫云| 沅江市| 清原| 台北市| 文成县| 方山县| 缙云县| 榆树市| 宣武区| 宜宾市| 凉山| 稷山县| 搜索| 绩溪县| 成武县|