Advertisement
pexea12

image processing js

May 30th, 2022
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. var fs = require("fs"),
  2. PNG = require("pngjs").PNG;
  3.  
  4. fs.createReadStream("./anh/test.png")
  5. .pipe(
  6. new PNG({
  7. filterType: 4,
  8. inputHasAlpha: false,
  9. })
  10. )
  11. .on("parsed", function () {
  12. console.log(this.height, this.width, this.data.length)
  13. const matData = [];
  14. for (let row = 0; row < this.height; ++row) {
  15. const rowData = [];
  16. for (let col = 0; col < this.width; ++col) {
  17. let idx = (this.width * row + col) << 2;
  18. rowData.push([ this.data[idx], this.data[idx + 1], this.data[idx + 2] ])
  19. }
  20. matData.push(rowData)
  21. }
  22.  
  23. console.log(matData, matData.length, matData[0].length);
  24.  
  25. this.pack().pipe(fs.createWriteStream("out.png"));
  26. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement