-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
51 lines (35 loc) · 1.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
var PSD = require('psd');
var fs = require('fs');
function psd2png(buffer) {
//var psd = PSD.fromFile(file.realpath);
var psd = new PSD(buffer);
psd.parse();
var png = psd.image.toPng();
var pngjs_require = './';
//var pngjs_require = './node_modules/psd/node_modules/pngjs/lib/';
var constants = require(pngjs_require + 'constants');
var Filter = require(pngjs_require + 'filter');
var Zlib = require('./node-zlib.js');
var packer = png._packer;
packer.pack2 = function(data, width, height) {
var datas = [];
// Signature
datas.push(new Buffer(constants.PNG_SIGNATURE));
datas.push(this._packIHDR(width, height));
// filter pixel data
var filter = new Filter(width, height, 4, data, this._options);
var data = filter.filter();
var compressed = new Zlib.deflateSync(data);
datas.push(this._packIDAT(compressed));
datas.push(this._packIEND());
var len = 0;
for (var i = 0; i < datas.length; i++) {
len += datas[i].length;
}
return Buffer.concat(datas, len);
};
var pngbuffer = packer.pack2(png.data, png.width, png.height);
return pngbuffer;
}
module.exports = psd2png;