Guest User

Untitled

a guest
Sep 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. function imageToBlob(image) {
  2. // Create a canvas to render the image on
  3. var canvas = document.createElement('canvas');
  4. canvas.width = image.width;
  5. canvas.height = image.height;
  6.  
  7. // Create a context and render the image
  8. var ctx = canvas.getContext('2d');
  9. ctx.drawImage(image, 0, 0, image.width, image.height);
  10.  
  11. // Get the image data
  12. var imageData = ctx.getImageData(0, 0, image.width, image.height).data;
  13.  
  14. // Create a blob with the imageData
  15. var blob = new Blob(imageData, {type: 'image'});
  16.  
  17. // Return the blob
  18. return blob;
  19. }
Add Comment
Please, Sign In to add comment