Advertisement
dragonfree97

Untitled

Apr 25th, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. // node script.js filename.txt
  2.  
  3. const {
  4. createCanvas,
  5. loadImage
  6. } = require('canvas')
  7. const fs = require('fs');
  8. const bigInt = require("big-integer");
  9.  
  10. var args = process.argv.slice(2)
  11.  
  12. var input = fs.readFileSync(args.join('')).toString();
  13. console.log("input loaded");
  14. var sanitized = input.replace(/[^0-9a-zA-Z]/g, "");
  15. console.log("input sanitized");
  16.  
  17. var image_data = bigInt(sanitized, 64).toString(2);
  18. var image_size = Math.ceil(Math.pow(image_data.length, 0.5));
  19. console.log("Image size: "+image_size);
  20. const canvas = createCanvas(image_size, image_size);
  21. const ctx = canvas.getContext('2d');
  22.  
  23. for (var i = 0; i < image_data.length; i++) {
  24. var x = i%image_size;
  25. var y = Math.floor(i/image_size);
  26. if (image_data[i] == "1") {
  27. ctx.fillStyle = "#000000";
  28. } else {
  29. ctx.fillStyle = "#FFFFFF";
  30. }
  31. ctx.fillRect( x, y, 1, 1 );
  32. if (y != Math.floor((i-1)/image_size)) {
  33. console.log("row "+y+" of "+image_size);
  34. }
  35. }
  36. var d = new Date();
  37. var fn = "output/test_"+(d.getTime())+".png";
  38. var out = fs.createWriteStream(fn)
  39. const stream = canvas.createPNGStream({
  40. quality: 0.95,
  41. chromaSubsampling: false
  42. })
  43. stream.pipe(out)
  44. out.on('finish', () => {
  45. return console.log("done");
  46. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement