mirror of
https://github.com/danbulant/pngjs
synced 2026-07-09 05:00:39 +00:00
checked background on test page
This commit is contained in:
parent
dc024a1b35
commit
207c02d323
4 changed files with 33 additions and 2 deletions
28
examples/test/bg.js
Normal file
28
examples/test/bg.js
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
var fs = require('fs'),
|
||||||
|
PNG = require('pngjs').PNG;
|
||||||
|
|
||||||
|
|
||||||
|
var png = new PNG({
|
||||||
|
width: 10,
|
||||||
|
height: 10,
|
||||||
|
filterType: -1
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
for (var y = 0; y < png.height; y++) {
|
||||||
|
for (var x = 0; x < png.width; x++) {
|
||||||
|
var idx = (png.width * y + x) << 2;
|
||||||
|
|
||||||
|
var col = x < (png.width >> 1) ^ y < (png.height >> 1) ? 0xe5 : 0xff;
|
||||||
|
|
||||||
|
png.data[idx ] = col;
|
||||||
|
png.data[idx+1] = col;
|
||||||
|
png.data[idx+2] = col;
|
||||||
|
png.data[idx+3] = 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
png.pipe(fs.createWriteStream('bg.png'));
|
||||||
|
png.pack();
|
||||||
BIN
examples/test/bg.png
Normal file
BIN
examples/test/bg.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 95 B |
|
|
@ -3,8 +3,8 @@
|
||||||
<head>
|
<head>
|
||||||
<title>PNG Test</title>
|
<title>PNG Test</title>
|
||||||
<style>
|
<style>
|
||||||
body { background: #0f0; font: 12px Arial; margin: 10px; }
|
body { background: #eee; font: 12px Arial; margin: 10px; }
|
||||||
img { margin: 2px; }
|
img { margin: 2px; background: url(bg.png); }
|
||||||
h3 { margin: 10px 0; }
|
h3 { margin: 10px 0; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ util.inherits(PNG, Parser);
|
||||||
|
|
||||||
PNG.prototype.pack = function() {
|
PNG.prototype.pack = function() {
|
||||||
this._pack(this.width, this.height, this.data);
|
this._pack(this.width, this.height, this.data);
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -76,11 +77,13 @@ PNG.prototype.parse = function(data, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this._parse(data);
|
this._parse(data);
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
PNG.prototype.write = function(data) {
|
PNG.prototype.write = function(data) {
|
||||||
this._buffers.push(data);
|
this._buffers.push(data);
|
||||||
this._buffLen += data.length;
|
this._buffLen += data.length;
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
PNG.prototype.end = function(data) {
|
PNG.prototype.end = function(data) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue