dev-master
9999999-dev https://github.com/jumper423/JavaScript-Canvas-to-BlobJavaScript Canvas to Blob is a function to convert canvas elements into Blob objects.
MIT
javascript conversion convert canvas blob
Wallogit.com
2017 © Pedro Peláez
JavaScript Canvas to Blob is a function to convert canvas elements into Blob objects.
Canvas to Blob is a polyfill for the standard JavaScript canvas.toBlob method., (*1)
npm i -S blueimp-canvas-to-blob
It can be used to create Blob objects from an HTML canvas element., (*2)
Include the (minified) JavaScript Canvas to Blob script in your HTML markup:, (*3)
<script src="js/canvas-to-blob.min.js"></script>
Then use the canvas.toBlob() method in the same way as the native implementation:, (*4)
var canvas = document.createElement('canvas');
/* ... your canvas manipulations ... */
if (canvas.toBlob) {
canvas.toBlob(
function (blob) {
// Do something with the blob object,
// e.g. creating a multipart form for file uploads:
var formData = new FormData();
formData.append('file', blob, fileName);
/* ... */
},
'image/jpeg'
);
}
The JavaScript Canvas to Blob function has zero dependencies., (*5)
However, Canvas to Blob is a very suitable complement to the JavaScript Load Image function., (*6)
In addition to the canvas.toBlob polyfill, the JavaScript Canvas to Blob script provides one additional function called dataURLtoBlob, which is added to the global window object if no AMD loader is used to load the script:, (*7)
// 80x60px GIF image (color black, base64 data):
var b64Data = 'R0lGODdhUAA8AIABAAAAAP///ywAAAAAUAA8AAACS4SPqcvtD6' +
'OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofE' +
'ovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5PKsAAA7',
imageUrl = 'data:image/gif;base64,' + b64Data,
blob = window.dataURLtoBlob && window.dataURLtoBlob(imageUrl);
The following browsers support either the native or the polyfill canvas.toBlob() method:, (*8)
JavaScript Canvas to Blob Test, (*9)
The JavaScript Canvas to Blob script is released under the MIT license., (*10)
JavaScript Canvas to Blob is a function to convert canvas elements into Blob objects.
MIT
javascript conversion convert canvas blob