New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

images

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

images - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

binding.js

98

index.js

@@ -1,16 +0,88 @@

var fs = require("fs"),
path = require("path"),
name = "images.node",
test, i, count, file;
var USE_OLD_API = false,
_images = require("./binding.js"),
_Image = _images.Image,
prototype;
test = [path.join(__dirname, "build", "Release", name),
path.join(__dirname, "lib", process.platform, name)];
function WrappedImage(width, height) {
if (!(this instanceof WrappedImage)) return new WrappedImage(width, height);
this._handle = new _Image(width, height);
}
count = test.length;
for (i = 0; i < count; i++){
file = test[i];
if (fs.existsSync(file)) {
module.exports = require(file);
break;
}
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);
},
fillColor: function(red, green, blue, alpha) {
this._handle.fillColor(red, green, blue, alpha);
},
drawImage: function(img, x, y) {
if (img instanceof WrappedImage) {
img = img._handle;
}
this._handle.drawImage(img, x, y);
},
toBuffer: function(type) {
//TODO fastBuffer
return this._handle.toBuffer(type);
},
size: function(width, height) {
//TODO set width and height
return {
width: this.width(),
height: this.height()
};
},
width: function(width) {
//TODO set width
return this._handle.width;
},
height: function(height) {
//TODO set height
return this._handle.height;
}
};
function bind(target, obj) {
var item,
slice = Array.prototype.slice;
for (item in obj) {
if (obj.hasOwnProperty(item)) {
target[item] = (function(fn) {
return function() {
var ret = fn.apply(this, slice.call(arguments, 0));
return ret === undefined ? this : ret;
};
})(obj[item]);
}
}
}
bind(WrappedImage.prototype, prototype);
module.exports = USE_OLD_API ? _images : {
TYPE_PNG: _images.TYPE_PNG,
TYPE_JPEG: _images.TYPE_JPEG,
TYPE_GIF: _images.TYPE_GIF,
TYPE_BMP: _images.TYPE_BMP,
TYPE_RAW: _images.TYPE_RAW,
Image: WrappedImage,
createImage: function(width, height) {
return WrappedImage(width, height);
},
loadFromBuffer: function(buffer, start, end) {
return WrappedImage().loadFromBuffer(buffer, start, end);
},
copyFromImage: function(src, x, y, width, height) {
return WrappedImage().copyFromImage(src, x, y, width, height);
}
};

13

install.js

@@ -1,13 +0,14 @@

var images = require("./index.js");
if (!images.Image) {
try {
require("./binding.js"); //try to load pre-build lib
} catch (e) {
// build addon
var spawn = require('child_process').spawn,
gyp = spawn('node-gyp', ['rebuild']);
gyp.stdout.pipe(process.stdout);
gyp.stderr.pipe(process.stderr);
gyp.stdout.pipe(process.stdout);
gyp.stderr.pipe(process.stderr);
gyp.on('exit', function(code) {
process.exit(code);
process.exit(code);
});
}
{
"name": "images",
"version": "1.0.2",
"version": "1.1.0",
"description": "Cross-platform image decoder(png/jpeg/gif) and encoder(png) for Nodejs",
"main": "index.js",
"scripts": {
"test": "node test/runAllTest.js",
"test": "node demo/runAllDemo.js",
"install": "node install.js"

@@ -9,0 +9,0 @@ },

@@ -11,35 +11,53 @@ node-images

``` js
var images = require('images'); //npm
// var images = require('./index.js'); //git
``` javascript
var images = require("images"), //npm
// images = require("./index.js"), //git
fs = require(""fs);
var img = new images.Image();
img.loadFromBuffer(fs.readFileSync("test/img/rotating_earth.gif"));
fs.writeFileSync("test/output/gif2png.png", img.toBuffer(images.TYPE_PNG));
var img = images.loadFromBuffer(fs.readFileSync("demo/img/rotating_earth.gif"));
fs.writeFileSync("demo/output/gif2png.png", img.toBuffer(images.TYPE_PNG));
```
## Api
## API
node-images provide jQuery-like Chaining API,
You can start the chain like this:
```javascript
images.createImage(width, height).XXXX()
// OR
images.loadFromBuffer(buffer[, start[, end]]).XXXX()
// OR
images.copyFromImage(image[, x, y, width, height]).XXXX()
```
### images.Image([width, heigth])
### .createImage(width, height)
Create a new transparent image
### loadFromBuffer(buffer[, start, [end]]);
See `test/loadFromBuffer.js`
### .loadFromBuffer(buffer[, start[, end]])
Load and decode image from a buffer
See `demo/loadFromBuffer.js`
### copyFromImage(x, y, width, height);
See `test/copyFromImage.js`
### .copyFromImage(image[, x, y, width, height])
Copy from another image
See `demo/copyFromImage.js`
### fillColor(red, green, blue[, alpha]);
See `test/fillColor.js`
### .fillColor(red, green, blue[, alpha])
See `demo/fillColor.js`
### drawImage(img, x, y);
See `test/drawImage.js`
### .drawImage(image, x, y)
See `demo/drawImage.js`
### toBuffer(type);
See `test/toBuffer.js`
### .size([width, height])
Return image size or **TODO:set image size**
```javascript
{
width:123,
height:456
}
```
### width
*readonly*
### .width([width])
Return image width or **TODO:set image width**
### height
*readonly*
### .height([height])
Return image height or **TODO:set image height**
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc