imagemin-upng
Advanced tools
Comparing version 1.1.0 to 1.2.0
37
index.js
@@ -1,25 +0,32 @@ | ||
'use strict'; | ||
'use strict' | ||
var isPng = require('is-png'); | ||
var UPNG = require('upng-js'); | ||
var UPNG = require('upng-js') | ||
var isPng = require('is-png') | ||
module.exports = function(options) { | ||
options = Object.assign({cnum: 256}, options); | ||
options = Object.assign({cnum: 256}, options) | ||
return function(buffer) { | ||
if (!Buffer.isBuffer(buffer)) { | ||
return Promise.reject(new TypeError('Expected a buffer')); | ||
return function(input) { | ||
if (!Buffer.isBuffer(input)) { | ||
return Promise.reject(new TypeError('Expected a buffer')) | ||
} | ||
if (!isPng(buffer)) { | ||
return Promise.resolve(buffer); | ||
if (!isPng(input)) { | ||
return Promise.resolve(input) | ||
} | ||
var img = UPNG.decode(buffer); | ||
var rgba = UPNG.toRGBA8(img); | ||
var img = UPNG.decode(input) | ||
var dels = img.frames.map(function(frame) { | ||
return frame.delay | ||
}) | ||
var rgba = UPNG.toRGBA8(img) | ||
var newBuffer = Buffer.from(UPNG.encode(rgba, img.width, img.height, options.cnum)); | ||
var buffer = Buffer.from( | ||
UPNG.encode(rgba, img.width, img.height, options.cnum, dels) | ||
) | ||
return Promise.resolve(newBuffer.byteLength < buffer.byteLength ? newBuffer : buffer); | ||
}; | ||
}; | ||
return Promise.resolve( | ||
buffer.byteLength < input.byteLength ? buffer : input | ||
) | ||
} | ||
} |
{ | ||
"name": "imagemin-upng", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "upng imagemin plugin", | ||
@@ -25,2 +25,4 @@ "license": "MIT", | ||
"optimize", | ||
"png", | ||
"apng", | ||
"upng", | ||
@@ -31,4 +33,11 @@ "upng-js" | ||
"is-png": "^1.0.0", | ||
"upng-js": "^1.0.0" | ||
"upng-js": "^2.0.0" | ||
}, | ||
"scripts": { | ||
"test": "eslint index.js && ava", | ||
"publish": "npm --registry=https://registry.npmjs.org/ publish" | ||
}, | ||
"devDependencies": { | ||
"ava": "*" | ||
} | ||
} |
@@ -12,3 +12,2 @@ # imagemin-upng | ||
## Usage | ||
@@ -48,5 +47,4 @@ | ||
## License | ||
MIT © [imagemin](https://github.com/imagemin) | ||
MIT © [fisker Cheung](https://github.com/fisker) |
Sorry, the diff of this file is not supported yet
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
3167
25
0
1
49
+ Addedupng-js@2.1.0(transitive)
- Removedupng-js@1.0.1(transitive)
Updatedupng-js@^2.0.0