Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # js_getImageData.py
- import tempfile
- import webbrowser
- import os
- js_data = '''<!DOCTYPE html>
- <html>
- <head>
- <title>HTML5 getImageData</title>
- <script>
- function draw() {
- var canvas = document.getElementById('myCanvas');
- var ctx = canvas.getContext('2d');
- ctx.translate(0.5, 0.5);
- ctx.lineWidth = 8;
- ctx.fillStyle = 'orange';
- ctx.fillRect(10, 10, 100, 100);
- ctx.strokeRect(10, 10, 100, 100);
- ctx.fillStyle = 'lightgreen';
- ctx.lineJoin = 'round';
- ctx.fillRect(130, 10, 100, 100);
- ctx.strokeRect(130, 10, 100, 100);
- let imageData = ctx.getImageData(60, 20, 100, 100);
- ctx.putImageData(imageData, 250, 10);
- }
- </script>
- </head>
- <body onload="draw();">
- <canvas id="myCanvas" width="450" height="350">
- </canvas>
- </body>
- </html>
- '''
- '''
- '''
- chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
- tf = tempfile.mktemp(".html", "JSdemo_")
- print tf
- with open(tf, 'w') as temp:
- temp.write(js_data)
- webbrowser.get(chrome_path).open(tf)
- os.remove(tf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement