Advertisement
here2share

# js_getImageData.py

Nov 26th, 2019
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. # js_getImageData.py
  2.  
  3. import tempfile
  4. import webbrowser
  5. import os
  6.  
  7. js_data = '''<!DOCTYPE html>
  8. <html>
  9. <head>
  10. <title>HTML5 getImageData</title>
  11. <script>
  12.    function draw() {
  13.        var canvas = document.getElementById('myCanvas');
  14.        var ctx = canvas.getContext('2d');
  15.        
  16.        ctx.translate(0.5, 0.5);  
  17.        ctx.lineWidth = 8;  
  18.  
  19.        ctx.fillStyle = 'orange';
  20.         ctx.fillRect(10, 10, 100, 100);
  21.        ctx.strokeRect(10, 10, 100, 100);
  22.  
  23.        ctx.fillStyle = 'lightgreen';
  24.        ctx.lineJoin = 'round';
  25.         ctx.fillRect(130, 10, 100, 100);
  26.        ctx.strokeRect(130, 10, 100, 100);
  27.        
  28.         let imageData = ctx.getImageData(60, 20, 100, 100);
  29.         ctx.putImageData(imageData, 250, 10);
  30.    }
  31. </script>
  32. </head>
  33.  
  34. <body onload="draw();">
  35.    <canvas id="myCanvas" width="450" height="350">
  36.    </canvas>
  37. </body>
  38. </html>
  39. '''
  40.  
  41. '''
  42. '''
  43.  
  44. chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
  45.  
  46. tf = tempfile.mktemp(".html", "JSdemo_")
  47. print tf
  48. with open(tf, 'w') as temp:
  49.     temp.write(js_data)
  50. webbrowser.get(chrome_path).open(tf)
  51. os.remove(tf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement