/node-npmdoc-images

Primary LanguageJavaScriptMIT LicenseMIT

api documentation for images (v3.0.0) npm package travis-ci.org build-status

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

NPM

apidoc

npmPackageListing

npmPackageDependencyTree

package.json

{
    "author": {
        "name": "ZhangYuanwei",
        "email": "zhangyuanwei1988@gmail.com"
    },
    "bindingMap": {
        "0.8.0": [
            "0.8.0",
            "0.8.25"
        ],
        "0.9.11": [
            "0.10.0",
            "0.10.99"
        ],
        "0.12.0": [
            "0.12.0",
            "0.12.99"
        ],
        "4.0.0": [
            "4.0.0",
            "4.99.99"
        ],
        "5.0.0": [
            "5.0.0",
            "5.99.99"
        ],
        "6.0.0": [
            "6.0.0",
            "6.99.99"
        ]
    },
    "bindingsCDN": "https://raw.githubusercontent.com/zhangyuanwei/node-images/master/bindings/",
    "bugs": {
        "url": "https://github.com/zhangyuanwei/node-images/issues"
    },
    "dependencies": {
        "nan": "^2.3.2"
    },
    "description": "Cross-platform image decoder(png/jpeg/gif) and encoder(png/jpeg) for Node.js",
    "devDependencies": {
        "step": "0.0.5"
    },
    "directories": {},
    "dist": {
        "shasum": "e1c3866b7884d671a581fedd511134620da86ea1",
        "tarball": "https://registry.npmjs.org/images/-/images-3.0.0.tgz"
    },
    "gitHead": "094470e68bdc0744d38b413322d5a0e098347a37",
    "gypfile": true,
    "homepage": "https://github.com/zhangyuanwei/node-images#readme",
    "keywords": [
        "image",
        "decoder",
        "encoder",
        "png",
        "jpeg",
        "gif",
        "cross-platform",
        "images"
    ],
    "license": "MIT",
    "main": "index.js",
    "maintainers": [
        {
            "name": "2betop",
            "email": "2betop.cn@gmail.com"
        },
        {
            "name": "fansekey",
            "email": "fansekey@gmail.com"
        },
        {
            "name": "fis-dev",
            "email": "fansekey@gmail.com"
        },
        {
            "name": "zhangyuanwei",
            "email": "zhangyuanwei1988@gmail.com"
        }
    ],
    "name": "images",
    "optionalDependencies": {},
    "readme": "ERROR: No README data found!",
    "repository": {
        "type": "git",
        "url": "git+https://github.com/zhangyuanwei/node-images.git"
    },
    "scripts": {
        "install": "echo \"Hello, World.\"",
        "test": "node test.js"
    },
    "version": "3.0.0"
}
  1. function images.Image (width, height)
  2. function images.copyFromImage (src, x, y, width, height)
  3. function images.createImage (width, height)
  4. function images.gc ()
  5. function images.getUsedMemory ()
  6. function images.loadFromBuffer (buffer, start, end)
  7. function images.loadFromFile (file)
  8. function images.setGCThreshold (value)
  9. function images.setLimit (maxWidth, maxHeight)
  10. number images.TYPE_BMP
  11. number images.TYPE_GIF
  12. number images.TYPE_JPEG
  13. number images.TYPE_PNG
  14. number images.TYPE_RAW
  15. object images.Image.prototype
  16. object images.binding
  1. function images.Image (width, height)
  1. function images.Image.prototype.copyFromImage ()
  2. function images.Image.prototype.draw ()
  3. function images.Image.prototype.drawImage ()
  4. function images.Image.prototype.encode ()
  5. function images.Image.prototype.fill ()
  6. function images.Image.prototype.fillColor ()
  7. function images.Image.prototype.height ()
  8. function images.Image.prototype.loadFromBuffer ()
  9. function images.Image.prototype.resize ()
  10. function images.Image.prototype.save ()
  11. function images.Image.prototype.saveAsync ()
  12. function images.Image.prototype.size ()
  13. function images.Image.prototype.toBuffer ()
  14. function images.Image.prototype.width ()
  1. function images.binding.Image ()
  2. function images.binding.gc ()
  3. number images.binding.TYPE_BMP
  4. number images.binding.TYPE_GIF
  5. number images.binding.TYPE_JPEG
  6. number images.binding.TYPE_PNG
  7. number images.binding.TYPE_RAW
  8. number images.binding.maxHeight
  9. number images.binding.maxWidth
  10. number images.binding.usedMemory
  • description and source-code
function WrappedImage(width, height) {
    if (!(this instanceof WrappedImage)) return new WrappedImage(width, height);
    if (gcThreshold && nextGCThreshold) {
        if (images.getUsedMemory() > nextGCThreshold) {
            images.gc();
            nextGCThreshold = images.getUsedMemory() + gcThreshold;
        }
    }
    this._handle = new _Image(width, height);
}
  • example usage
n/a
  • description and source-code
copyFromImage = function (src, x, y, width, height) {
    return WrappedImage().copyFromImage(src, x, y, width, height);
}
  • example usage
...
loadFromBuffer: function(buffer, start, end) {
    this._handle.loadFromBuffer(buffer, start, end);
},
copyFromImage: function(img, x, y, width, height) {
    if (img instanceof WrappedImage) {
        img = img._handle;
    }
    this._handle.copyFromImage(img, x, y, width, height);
},
fill: function(red, green, blue, alpha) {
    this._handle.fillColor(red, green, blue, alpha);
},
draw: function(img, x, y) {
    if (img instanceof WrappedImage) {
        img = img._handle;
...
  • description and source-code
createImage = function (width, height) {
    return WrappedImage(width, height);
}
  • example usage
n/a
  • description and source-code
gc = function () {
    return _images.gc();
}
  • example usage
...
Set the garbage collection threshold
设置图像处理库自动gc的阈值(当*新增*内存使用超过该阈值时,执行垃圾回收)

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

### images.gc()
Forced call garbage collection
强制调用V8的垃圾回收机制
...
  • description and source-code
getUsedMemory = function () {
    return _images.usedMemory;
}
  • example usage
...
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的垃圾回收机制
...
  • description and source-code
loadFromBuffer = function (buffer, start, end) {
    return WrappedImage().loadFromBuffer(buffer, start, end);
}
  • example usage
...
    }
}
this._handle = new _Image(width, height);
}

prototype = {
loadFromBuffer: function(buffer, start, end) {
    this._handle.loadFromBuffer(buffer, start, end);
},
copyFromImage: function(img, x, y, width, height) {
    if (img instanceof WrappedImage) {
        img = img._handle;
    }
    this._handle.copyFromImage(img, x, y, width, height);
},
...
  • description and source-code
loadFromFile = function (file) {
    return images.loadFromBuffer(fs.readFileSync(file));
}
  • example usage
n/a
  • description and source-code
setGCThreshold = function (value) {
    gcThreshold = value;
    nextGCThreshold = value;
}
  • example usage
...
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)
得到图像处理库占用的内存大小(单位为字节)
...
  • description and source-code
setLimit = function (maxWidth, maxHeight) {
    _images.maxHeight = maxHeight;
    _images.maxWidth = maxWidth;
    return images;
}
  • example usage
...
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的阈值(当*新增*内存使用超过该阈值时,执行垃圾回收)
...
  • description and source-code
function WrappedImage(width, height) {
    if (!(this instanceof WrappedImage)) return new WrappedImage(width, height);
    if (gcThreshold && nextGCThreshold) {
        if (images.getUsedMemory() > nextGCThreshold) {
            images.gc();
            nextGCThreshold = images.getUsedMemory() + gcThreshold;
        }
    }
    this._handle = new _Image(width, height);
}
  • example usage
n/a
  • description and source-code
copyFromImage = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...
loadFromBuffer: function(buffer, start, end) {
    this._handle.loadFromBuffer(buffer, start, end);
},
copyFromImage: function(img, x, y, width, height) {
    if (img instanceof WrappedImage) {
        img = img._handle;
    }
    this._handle.copyFromImage(img, x, y, width, height);
},
fill: function(red, green, blue, alpha) {
    this._handle.fillColor(red, green, blue, alpha);
},
draw: function(img, x, y) {
    if (img instanceof WrappedImage) {
        img = img._handle;
...
  • description and source-code
draw = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...
''' javascript
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 功能特性
...
  • description and source-code
drawImage = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...
fill: function(red, green, blue, alpha) {
    this._handle.fillColor(red, green, blue, alpha);
},
draw: function(img, x, y) {
    if (img instanceof WrappedImage) {
        img = img._handle;
    }
    this._handle.drawImage(img, x, y);
},
encode: function(type, config) {
    var configurator;
    if (typeof(type) != "number") {
        type = String(type).toLowerCase();
        type = (FILE_TYPE_MAP["." + type] || FILE_TYPE_MAP[type]);
    }
...
  • description and source-code
encode = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...
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**
**注意:该操作将会切断调用链**
...
  • description and source-code
fill = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...
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* 图像
...
  • description and source-code
fillColor = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...
copyFromImage: function(img, x, y, width, height) {
    if (img instanceof WrappedImage) {
        img = img._handle;
    }
    this._handle.copyFromImage(img, x, y, width, height);
},
fill: function(red, green, blue, alpha) {
    this._handle.fillColor(red, green, blue, alpha);
},
draw: function(img, x, y) {
    if (img instanceof WrappedImage) {
        img = img._handle;
    }
    this._handle.drawImage(img, x, y);
},
...
  • description and source-code
height = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...
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
设置库处理图片的大小限制,设置后对所有新的操作生效(如果超限则抛出异常)
...
  • description and source-code
loadFromBuffer = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...
    }
}
this._handle = new _Image(width, height);
}

prototype = {
loadFromBuffer: function(buffer, start, end) {
    this._handle.loadFromBuffer(buffer, start, end);
},
copyFromImage: function(img, x, y, width, height) {
    if (img instanceof WrappedImage) {
        img = img._handle;
    }
    this._handle.copyFromImage(img, x, y, width, height);
},
...
  • description and source-code
resize = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...
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
获取或设置图像宽度
...
  • description and source-code
save = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...

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 功能特性

* Lightweight:no need to install any image processing library.
* 轻量级:无需安装任何图像处理库。
...
  • description and source-code
saveAsync = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
n/a
  • description and source-code
size = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...
Node.js轻量级跨平台图像编解码库

''' javascript
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
	});
'''
...
  • description and source-code
toBuffer = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...
        type = String(type).toLowerCase();
        type = (FILE_TYPE_MAP["." + type] || FILE_TYPE_MAP[type]);
    }
    if (config != undefined) {
        configurator = CONFIG_GENERATOR[type];
        config = configurator && configurator(config);
    }
    return this._handle.toBuffer(type, config);
},
save: function(file, type, config) {
    if (type && typeof(type) == "object") {
        config = type;
        type = undefined;
    }
    fs.writeFileSync(file, this.encode(type || path.extname(file), config));
...
  • description and source-code
width = function () {
    var ret = fn.apply(this, slice.call(arguments, 0));
    return ret === undefined ? this : ret;
}
  • example usage
...
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
获取或设置图像高度
...
  • description and source-code
function Image() { [native code] }
  • example usage
n/a
  • description and source-code
function gc() { [native code] }
  • example usage
...
Set the garbage collection threshold
设置图像处理库自动gc的阈值(当*新增*内存使用超过该阈值时,执行垃圾回收)

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

### images.gc()
Forced call garbage collection
强制调用V8的垃圾回收机制
...

misc

  • this document was created with utility2