Guest User

Posting images to /r/layer

a guest
Oct 20th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. // How to post images to /r/layer
  2.  
  3. // First, get an image you want to post, make sure it's a PNG
  4. // Use https://base64.guru/converter/encode/image to get the image as base64
  5. // Keep the text from the output handy
  6.  
  7. // Using Chrome...
  8. // Create a new layer, the Layer creation itnterface will open
  9. // Click to create at least one line or dot with the standard paint tool
  10. // Right click within the layer maker window and click 'inspect'
  11. // In the elements tab of Chrome Dev Tools, click on the line which begins with '<layer-maker'
  12. // Navigate to the console tab in Chrome Dev Tools
  13. // Paste the following
  14. let layerMaker = document.getElementsByTagName('layer-maker')[0];
  15. const imageToPost = new Image();
  16. let layerUndoReplacer = function(undoManager, imageData){
  17. for(let i = 0; i < undoManager.states.length; i++){
  18. let state = undoManager.states[i];
  19. state.next = {
  20. imageData: imageData,
  21. x: 0, y: 0
  22. }
  23. state.prev = {
  24. imageData: imageData,
  25. x: 0, y: 0
  26. }
  27. }
  28. }
  29.  
  30. // Paste your Base64 data in here,, after the comma and ending with the last double quotes
  31. imageToPost.src = "data:image/png;base64,YOURBASE64HERE"
  32. layerMaker.canvas.ctxDisplay.drawImage(imageToPost, 0, 0, 1000, 1000)
  33. let imageData = layerMaker.canvas.ctxDisplay.getImageData(0,0,1000,1000);
  34. layerUndoReplacer(layerMaker.canvas.undoManager, imageData);
  35.  
  36. // Press undo/redo until the image looks correct
  37. // Submit and enjoy!
Add Comment
Please, Sign In to add comment