Playground for blob-util
Welcome to the docs and playground for blob-util!
Below you'll find API documentation, as well as a little Kirby GIF you can play around with.

Here's some code to get you started. Copy-paste this into your console:
var img = document.getElementById('kirby');
blobUtil.imgSrcToBlob(img.src).then(function (blob) {
var blobURL = blobUtil.createObjectURL(blob);
var newImg = document.createElement('img');
newImg.src = blobURL;
img.parentNode.appendChild(newImg);
});
If you see two Kirbys, you're on your way!
Methods
-
arrayBufferToBlob(buffer, type) → {Promise}
-
Convert an
ArrayBufferto aBlob. Returns a Promise.Parameters:
Name Type Description bufferArrayBuffer typestring | undefined the content type (optional) Returns:
Promise that resolves with theBlob- Type
- Promise
-
base64StringToBlob(base64, type) → {Promise}
-
Convert a base64-encoded string to a
Blob. Returns a Promise.Parameters:
Name Type Description base64string typestring | undefined the content type (optional) Returns:
Promise that resolves with theBlob- Type
- Promise
-
binaryStringToBlob(binary, type) → {Promise}
-
Convert a binary string to a
Blob. Returns a Promise.Parameters:
Name Type Description binarystring typestring | undefined the content type (optional) Returns:
Promise that resolves with theBlob- Type
- Promise
-
blobToArrayBuffer(blob) → {Promise}
-
Convert a
Blobto anArrayBuffer. Returns a Promise.Parameters:
Name Type Description blobBlob Returns:
Promise that resolves with theArrayBuffer- Type
- Promise
-
blobToBase64String(blob) → {Promise}
-
Convert a
Blobto a binary string. Returns a Promise.Parameters:
Name Type Description blobBlob Returns:
Promise that resolves with the binary string- Type
- Promise
-
blobToBinaryString(blob) → {Promise}
-
Convert a
Blobto a binary string. Returns a Promise.Parameters:
Name Type Description blobBlob Returns:
Promise that resolves with the binary string- Type
- Promise
-
canvasToBlob(canvas, type) → {Promise}
-
Convert a
canvasto aBlob. Returns a Promise.Parameters:
Name Type Description canvasstring typestring | undefined the content type (optional, defaults to 'image/png') Returns:
Promise that resolves with theBlob- Type
- Promise
-
createBlob(parts, options) → {Blob}
-
Shim for new Blob() to support older browsers that use the deprecated
BlobBuilderAPI.Parameters:
Name Type Description partsArray content of the BloboptionsObject usually just {type: myContentType}Returns:
- Type
- Blob
-
createObjectURL(blob) → {string}
-
Shim for URL.createObjectURL() to support browsers that only have the prefixed
webkitURL(e.g. Android <4.4).Parameters:
Name Type Description blobBlob Returns:
url- Type
- string
-
dataURLToBlob(dataURL) → {Promise}
-
Convert a data URL string (e.g.
'data:image/png;base64,iVBORw0KG...') to aBlob. Returns a Promise.Parameters:
Name Type Description dataURLstring Returns:
Promise that resolves with theBlob- Type
- Promise
-
imgSrcToBlob(src, type, crossOrigin) → {Promise}
-
Convert an image's
srcURL to aBlobby loading the image and painting it to acanvas. Returns a Promise. Note: this will coerce the image to the desired content type, and it will only paint the first frame of an animated GIF.Parameters:
Name Type Description srcstring typestring | undefined the content type (optional, defaults to 'image/png') crossOriginstring | undefined for CORS-enabled images, set this to 'Anonymous' to avoid "tainted canvas" errors Returns:
Promise that resolves with theBlob- Type
- Promise
-
imgSrcToDataURL(src, type, crossOrigin) → {Promise}
-
Convert an image's
srcURL to a data URL by loading the image and painting it to acanvas. Returns a Promise. Note: this will coerce the image to the desired content type, and it will only paint the first frame of an animated GIF.Parameters:
Name Type Description srcstring typestring | undefined the content type (optional, defaults to 'image/png') crossOriginstring | undefined for CORS-enabled images, set this to 'Anonymous' to avoid "tainted canvas" errors Returns:
Promise that resolves with the data URL string- Type
- Promise
-
revokeObjectURL(url)
-
Shim for URL.revokeObjectURL() to support browsers that only have the prefixed
webkitURL(e.g. Android <4.4).Parameters:
Name Type Description urlstring