Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function imageToBlob(image) {
- // Create a canvas to render the image on
- var canvas = document.createElement('canvas');
- canvas.width = image.width;
- canvas.height = image.height;
- // Create a context and render the image
- var ctx = canvas.getContext('2d');
- ctx.drawImage(image, 0, 0, image.width, image.height);
- // Get the image data
- var imageData = ctx.getImageData(0, 0, image.width, image.height).data;
- // Create a blob with the imageData
- var blob = new Blob(imageData, {type: 'image'});
- // Return the blob
- return blob;
- }
Add Comment
Please, Sign In to add comment