You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This will install the JavaScript files inside
./node_modules/blueimp-canvas-to-blob/js/ relative to your current directory,
from where you can copy them into a folder that is served by your web server.
Next include the minified JavaScript Canvas to Blob script in your HTML markup:
<scriptsrc="js/canvas-to-blob.min.js"></script>
Or alternatively, include the non-minified version:
<scriptsrc="js/canvas-to-blob.js"></script>
Usage
You can use the canvas.toBlob() method in the same way as the native
implementation:
varcanvas=document.createElement('canvas')// Edit the canvas ...if(canvas.toBlob){canvas.toBlob(function(blob){// Do something with the blob object,// e.g. create multipart form data for file uploads:varformData=newFormData()formData.append('file',blob,'image.jpg')// ...},'image/jpeg')}
Requirements
The JavaScript Canvas to Blob function has zero dependencies.
In addition to the canvas.toBlob() polyfill, the JavaScript Canvas to Blob
script exposes its helper function dataURLtoBlob(url):
// Uncomment the following line when using a module loader like webpack:// var dataURLtoBlob = require('blueimp-canvas-to-blob')// black+white 3x2 GIF, base64 data:varb64='R0lGODdhAwACAPEAAAAAAP///yZFySZFySH5BAEAAAIALAAAAAADAAIAAAIDRAJZADs='varurl='data:image/gif;base64,'+b64varblob=dataURLtoBlob(url)