Guest User

Untitled

a guest
Jan 16th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4. <head>
  5. <title>MemeMaker-Simple</title>
  6.  
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  8. <meta name="mobile-web-app-capable" content="yes">
  9. <meta name="apple-mobile-web-app-capable" content="yes">
  10. <style>
  11. #image-container {
  12. display: flex;
  13. }
  14. </style>
  15. </head>
  16.  
  17. <body>
  18.  
  19. <div>
  20. <input type="file" id="file" />
  21. </div>
  22. <div id="image-container">
  23. <canvas width="500" height="500"></canvas>
  24. <div>
  25. <span>Top Line:</span><br/>
  26. <input id="topLineText" type="text"><br/>
  27. <span>Bottom Line:</span><br/>
  28. <input id="bottomLineText" type="text"><br/>
  29. <button id="saveBtn">Save</button>
  30. </div>
  31. </div>
  32. <script>
  33. function textChangeListener (evt) {
  34. var id = evt.target.id;
  35. var text = evt.target.value;
  36.  
  37. if (id == "topLineText") {
  38. window.topLineText = text;
  39. } else {
  40. window.bottomLineText = text;
  41. }
  42.  
  43. redrawMeme(window.imageSrc, window.topLineText, window.bottomLineText);
  44. }
  45.  
  46. function redrawMeme(image, topLine, bottomLine) {
  47. // Get Canvas2DContext
  48. var canvas = document.querySelector('canvas');
  49. var ctx = canvas.getContext("2d");
  50. // Your code here
  51. }
  52.  
  53. function saveFile() {
  54. window.open(document.querySelector('canvas').toDataURL());
  55. }
  56.  
  57.  
  58. function handleFileSelect(evt) {
  59. var canvasWidth = 500;
  60. var canvasHeight = 500;
  61. var file = evt.target.files[0];
  62.  
  63.  
  64.  
  65. var reader = new FileReader();
  66. reader.onload = function(fileObject) {
  67. var data = fileObject.target.result;
  68.  
  69. // Create an image object
  70. var image = new Image();
  71. image.onload = function() {
  72.  
  73. window.imageSrc = this;
  74. redrawMeme(window.imageSrc, null, null);
  75. }
  76.  
  77. // Set image data to background image.
  78. image.src = data;
  79. console.log(fileObject.target.result);
  80. };
  81. reader.readAsDataURL(file)
  82. }
  83.  
  84. window.topLineText = "";
  85. window.bottomLineText = "";
  86. var input1 = document.getElementById('topLineText');
  87. var input2 = document.getElementById('bottomLineText');
  88. input1.oninput = textChangeListener;
  89. input2.oninput = textChangeListener;
  90. document.getElementById('file').addEventListener('change', handleFileSelect, false);
  91. document.querySelector('button').addEventListener('click', saveFile, false);
  92. </script>
  93.  
  94. </body>
  95. </html>
Add Comment
Please, Sign In to add comment