Comparing version
@@ -20,2 +20,13 @@ 'use strict'; | ||
var bgColor = options.bgColor || {}; | ||
if (bgColor.red === undefined) { | ||
bgColor.red = 255; | ||
} | ||
if (bgColor.green === undefined) { | ||
bgColor.green = 255; | ||
} | ||
if (bgColor.blue === undefined) { | ||
bgColor.blue = 255; | ||
} | ||
for (var y = 0; y < height; y++) { | ||
@@ -30,2 +41,8 @@ for (var x = 0; x < width; x++) { | ||
alpha = data[inIndex + 3]; | ||
if (!outHasAlpha) { | ||
alpha /= 255; | ||
red = Math.min(Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0), 255); | ||
green = Math.min(Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0), 255); | ||
blue = Math.min(Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0), 255); | ||
} | ||
} | ||
@@ -49,2 +66,2 @@ else { | ||
return outData; | ||
}; | ||
}; |
@@ -0,0 +0,0 @@ 'use strict'; |
{ | ||
"name": "pngjs", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "PNG encoder/decoder in pure JS, supporting any bit size & interlace, async & sync with full test suite.", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
@@ -1,2 +0,2 @@ | ||
[](https://travis-ci.org/lukeapage/pngjs2) [](https://ci.appveyor.com/project/lukeapage/pngjs2/branch/master) [](https://coveralls.io/github/lukeapage/pngjs2?branch=master) [](http://badge.fury.io/js/pngjs2) | ||
[](https://travis-ci.org/lukeapage/pngjs) [](https://ci.appveyor.com/project/lukeapage/pngjs2/branch/master) [](https://coveralls.io/github/lukeapage/pngjs2?branch=master) [](http://badge.fury.io/js/pngjs) | ||
@@ -118,2 +118,4 @@ pngjs | ||
- `inputHasAlpha` - whether the input bitmap has 4 bits per pixel (rgb and alpha) or 3 (rgb - no alpha). | ||
- `bgColor` - an object containing red, green, and blue values between 0 and 255 | ||
that is used when packing a PNG if alpha is not to be included (default: 255,255,255) | ||
@@ -210,2 +212,26 @@ | ||
## Packing a PNG and removing alpga (RGBA to RGB) | ||
When removing the alpha channel from an image, there needs to be a background color to correctly | ||
convert each pixel's transparency to the appropriate RGB value. By default, pngjs will flatten | ||
the image against a white background. You can override this in the options: | ||
```js | ||
var fs = require('fs'), | ||
PNG = require('pngjs').PNG; | ||
fs.createReadStream('in.png') | ||
.pipe(new PNG({ | ||
colorType: 2, | ||
bgColor: { | ||
red: 0, | ||
green: 255, | ||
blue: 0 | ||
} | ||
})) | ||
.on('parsed', function() { | ||
this.pack().pipe(fs.createWriteStream('out.png')); | ||
}); | ||
``` | ||
# Sync API | ||
@@ -238,2 +264,6 @@ | ||
### 2.1.0 - 28/10/2015 | ||
- rename package to pngjs | ||
- added 'bgColor' option | ||
### 2.0.0 - 08/10/2015 | ||
@@ -240,0 +270,0 @@ - fixes to readme |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
709056
571.29%78
143.75%2316
51.08%322
10.27%0
-100%