Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blob-util

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blob-util - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

doc/fonts/OpenSans-Bold-webfont.eot

22

api.md

@@ -13,5 +13,5 @@ ###Index

* [dataURLToBlob(dataURL)](#dataURLToBlob)
* [imgSrcToDataURL(src, type)](#imgSrcToDataURL)
* [canvasToBlob(canvas, type)](#canvasToBlob)
* [imgSrcToBlob(src, type)](#imgSrcToBlob)
* [imgSrcToDataURL(src, type, crossOrigin, quality)](#imgSrcToDataURL)
* [canvasToBlob(canvas, type, quality)](#canvasToBlob)
* [imgSrcToBlob(src, type, crossOrigin, quality)](#imgSrcToBlob)
* [arrayBufferToBlob(buffer, type)](#arrayBufferToBlob)

@@ -106,3 +106,3 @@ * [blobToArrayBuffer(blob)](#blobToArrayBuffer)

<a name="imgSrcToDataURL"></a>
###imgSrcToDataURL(src, type)
###imgSrcToDataURL(src, type, crossOrigin, quality)
Convert an image's <code>src</code> URL to a data URL by loading the image and painting

@@ -118,6 +118,10 @@ it to a <code>canvas</code>. Returns a Promise.

- type `string` | `undefined` - the content type (optional, defaults to 'image/png')
- crossOrigin `string` | `undefined` - for CORS-enabled images, set this to
'Anonymous' to avoid "tainted canvas" errors
- quality `number` | `undefined` - a number between 0 and 1 indicating image quality
if the requested type is 'image/jpeg' or 'image/webp'
**Returns**: `Promise` - Promise that resolves with the data URL string
<a name="canvasToBlob"></a>
###canvasToBlob(canvas, type)
###canvasToBlob(canvas, type, quality)
Convert a <code>canvas</code> to a <code>Blob</code>. Returns a Promise.

@@ -129,6 +133,8 @@

- type `string` | `undefined` - the content type (optional, defaults to 'image/png')
- quality `number` | `undefined` - a number between 0 and 1 indicating image quality
if the requested type is 'image/jpeg' or 'image/webp'
**Returns**: `Promise` - Promise that resolves with the <code>Blob</code>
<a name="imgSrcToBlob"></a>
###imgSrcToBlob(src, type)
###imgSrcToBlob(src, type, crossOrigin, quality)
Convert an image's <code>src</code> URL to a <code>Blob</code> by loading the image and painting

@@ -144,2 +150,6 @@ it to a <code>canvas</code>. Returns a Promise.

- type `string` | `undefined` - the content type (optional, defaults to 'image/png')
- crossOrigin `string` | `undefined` - for CORS-enabled images, set this to
'Anonymous' to avoid "tainted canvas" errors
- quality `number` | `undefined` - a number between 0 and 1 indicating image quality
if the requested type is 'image/jpeg' or 'image/webp'

@@ -146,0 +156,0 @@ **Returns**: `Promise` - Promise that resolves with the <code>Blob</code>

{
"name": "blob-util",
"version": "1.1.2",
"version": "1.2.0",
"description": "Utilities for working with Blob objects in the browser",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/nolanlawson/blob-util",

@@ -102,24 +102,190 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.blobUtil = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){

},{}],2:[function(_dereq_,module,exports){
'use strict';
var types = [
_dereq_(5),
_dereq_(4),
_dereq_(3),
_dereq_(6),
_dereq_(7)
];
var draining;
var currentQueue;
var queueIndex = -1;
var queue = [];
var scheduled = false;
function cleanUpNextTick() {
draining = false;
if (currentQueue && currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
nextTick();
}
}
},{}],3:[function(_dereq_,module,exports){
//named nextTick for less confusing stack traces
function nextTick() {
scheduled = false;
draining = true;
var len = queue.length;
var timeout = setTimeout(cleanUpNextTick);
while (len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
currentQueue[queueIndex].run();
}
queueIndex = -1;
len = queue.length;
}
queueIndex = -1;
draining = false;
clearTimeout(timeout);
}
var scheduleDrain;
var i = -1;
var len = types.length;
while (++i < len) {
if (types[i] && types[i].test && types[i].test()) {
scheduleDrain = types[i].install(nextTick);
break;
}
}
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
module.exports = immediate;
function immediate(task) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(task, args));
if (!scheduled && !draining) {
scheduled = true;
scheduleDrain();
}
}
},{"3":3,"4":4,"5":5,"6":6,"7":7}],3:[function(_dereq_,module,exports){
(function (global){
if (typeof global.Promise === 'function') {
module.exports = global.Promise;
} else {
module.exports = _dereq_(7);
}
'use strict';
exports.test = function () {
if (global.setImmediate) {
// we can only get here in IE10
// which doesn't handel postMessage well
return false;
}
return typeof global.MessageChannel !== 'undefined';
};
exports.install = function (func) {
var channel = new global.MessageChannel();
channel.port1.onmessage = func;
return function () {
channel.port2.postMessage(0);
};
};
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"7":7}],4:[function(_dereq_,module,exports){
},{}],4:[function(_dereq_,module,exports){
(function (global){
'use strict';
//based off rsvp https://github.com/tildeio/rsvp.js
//license https://github.com/tildeio/rsvp.js/blob/master/LICENSE
//https://github.com/tildeio/rsvp.js/blob/master/lib/rsvp/asap.js
var Mutation = global.MutationObserver || global.WebKitMutationObserver;
exports.test = function () {
return Mutation;
};
exports.install = function (handle) {
var called = 0;
var observer = new Mutation(handle);
var element = global.document.createTextNode('');
observer.observe(element, {
characterData: true
});
return function () {
element.data = (called = ++called % 2);
};
};
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],5:[function(_dereq_,module,exports){
(function (process){
'use strict';
exports.test = function () {
// Don't get fooled by e.g. browserify environments.
return (typeof process !== 'undefined') && !process.browser;
};
exports.install = function (func) {
return function () {
process.nextTick(func);
};
};
}).call(this,_dereq_(21))
},{"21":21}],6:[function(_dereq_,module,exports){
(function (global){
'use strict';
exports.test = function () {
return 'document' in global && 'onreadystatechange' in global.document.createElement('script');
};
exports.install = function (handle) {
return function () {
// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
var scriptEl = global.document.createElement('script');
scriptEl.onreadystatechange = function () {
handle();
scriptEl.onreadystatechange = null;
scriptEl.parentNode.removeChild(scriptEl);
scriptEl = null;
};
global.document.documentElement.appendChild(scriptEl);
return handle;
};
};
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],7:[function(_dereq_,module,exports){
'use strict';
exports.test = function () {
return true;
};
exports.install = function (t) {
return function () {
setTimeout(t, 0);
};
};
},{}],8:[function(_dereq_,module,exports){
'use strict';
module.exports = INTERNAL;
function INTERNAL() {}
},{}],5:[function(_dereq_,module,exports){
},{}],9:[function(_dereq_,module,exports){
'use strict';
var Promise = _dereq_(8);
var reject = _dereq_(10);
var resolve = _dereq_(11);
var INTERNAL = _dereq_(4);
var handlers = _dereq_(6);
var Promise = _dereq_(12);
var reject = _dereq_(14);
var resolve = _dereq_(15);
var INTERNAL = _dereq_(8);
var handlers = _dereq_(10);
var noArray = reject(new TypeError('must be an array'));

@@ -162,7 +328,7 @@ module.exports = function all(iterable) {

};
},{"10":10,"11":11,"4":4,"6":6,"8":8}],6:[function(_dereq_,module,exports){
},{"10":10,"12":12,"14":14,"15":15,"8":8}],10:[function(_dereq_,module,exports){
'use strict';
var tryCatch = _dereq_(14);
var resolveThenable = _dereq_(12);
var states = _dereq_(13);
var tryCatch = _dereq_(18);
var resolveThenable = _dereq_(16);
var states = _dereq_(17);

@@ -209,16 +375,16 @@ exports.resolve = function (self, value) {

}
},{"12":12,"13":13,"14":14}],7:[function(_dereq_,module,exports){
module.exports = exports = _dereq_(8);
},{"16":16,"17":17,"18":18}],11:[function(_dereq_,module,exports){
module.exports = exports = _dereq_(12);
exports.resolve = _dereq_(11);
exports.reject = _dereq_(10);
exports.all = _dereq_(5);
},{"10":10,"11":11,"5":5,"8":8}],8:[function(_dereq_,module,exports){
exports.resolve = _dereq_(15);
exports.reject = _dereq_(14);
exports.all = _dereq_(9);
},{"12":12,"14":14,"15":15,"9":9}],12:[function(_dereq_,module,exports){
'use strict';
var unwrap = _dereq_(15);
var INTERNAL = _dereq_(4);
var resolveThenable = _dereq_(12);
var states = _dereq_(13);
var QueueItem = _dereq_(9);
var unwrap = _dereq_(19);
var INTERNAL = _dereq_(8);
var resolveThenable = _dereq_(16);
var states = _dereq_(17);
var QueueItem = _dereq_(13);

@@ -262,6 +428,6 @@ module.exports = Promise;

},{"12":12,"13":13,"15":15,"4":4,"9":9}],9:[function(_dereq_,module,exports){
},{"13":13,"16":16,"17":17,"19":19,"8":8}],13:[function(_dereq_,module,exports){
'use strict';
var handlers = _dereq_(6);
var unwrap = _dereq_(15);
var handlers = _dereq_(10);
var unwrap = _dereq_(19);

@@ -292,8 +458,8 @@ module.exports = QueueItem;

};
},{"15":15,"6":6}],10:[function(_dereq_,module,exports){
},{"10":10,"19":19}],14:[function(_dereq_,module,exports){
'use strict';
var Promise = _dereq_(8);
var INTERNAL = _dereq_(4);
var handlers = _dereq_(6);
var Promise = _dereq_(12);
var INTERNAL = _dereq_(8);
var handlers = _dereq_(10);
module.exports = reject;

@@ -305,8 +471,8 @@

}
},{"4":4,"6":6,"8":8}],11:[function(_dereq_,module,exports){
},{"10":10,"12":12,"8":8}],15:[function(_dereq_,module,exports){
'use strict';
var Promise = _dereq_(8);
var INTERNAL = _dereq_(4);
var handlers = _dereq_(6);
var Promise = _dereq_(12);
var INTERNAL = _dereq_(8);
var handlers = _dereq_(10);
module.exports = resolve;

@@ -341,6 +507,6 @@

}
},{"4":4,"6":6,"8":8}],12:[function(_dereq_,module,exports){
},{"10":10,"12":12,"8":8}],16:[function(_dereq_,module,exports){
'use strict';
var handlers = _dereq_(6);
var tryCatch = _dereq_(14);
var handlers = _dereq_(10);
var tryCatch = _dereq_(18);
function safelyResolveThenable(self, thenable) {

@@ -375,3 +541,3 @@ // Either fulfill, reject or reject with error

exports.safely = safelyResolveThenable;
},{"14":14,"6":6}],13:[function(_dereq_,module,exports){
},{"10":10,"18":18}],17:[function(_dereq_,module,exports){
// Lazy man's symbols for states

@@ -382,3 +548,3 @@

exports.PENDING = ['PENDING'];
},{}],14:[function(_dereq_,module,exports){
},{}],18:[function(_dereq_,module,exports){
'use strict';

@@ -399,7 +565,7 @@

}
},{}],15:[function(_dereq_,module,exports){
},{}],19:[function(_dereq_,module,exports){
'use strict';
var immediate = _dereq_(16);
var handlers = _dereq_(6);
var immediate = _dereq_(2);
var handlers = _dereq_(10);
module.exports = unwrap;

@@ -422,150 +588,76 @@

}
},{"16":16,"6":6}],16:[function(_dereq_,module,exports){
'use strict';
var types = [
_dereq_(2),
_dereq_(18),
_dereq_(17),
_dereq_(19),
_dereq_(20)
];
var draining;
var currentQueue;
var queueIndex = -1;
},{"10":10,"2":2}],20:[function(_dereq_,module,exports){
(function (global){
if (typeof global.Promise === 'function') {
module.exports = global.Promise;
} else {
module.exports = _dereq_(11);
}
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"11":11}],21:[function(_dereq_,module,exports){
// shim for using process in browser
var process = module.exports = {};
var queue = [];
function cleanUpNextTick() {
draining = false;
if (currentQueue && currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
var draining = false;
function drainQueue() {
if (draining) {
return;
}
if (queue.length) {
nextTick();
draining = true;
var currentQueue;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
var i = -1;
while (++i < len) {
currentQueue[i]();
}
len = queue.length;
}
draining = false;
}
//named nextTick for less confusing stack traces
function nextTick() {
draining = true;
var len = queue.length;
var timeout = setTimeout(cleanUpNextTick);
while (len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
currentQueue[queueIndex]();
process.nextTick = function (fun) {
queue.push(fun);
if (!draining) {
setTimeout(drainQueue, 0);
}
queueIndex = -1;
len = queue.length;
}
queueIndex = -1;
draining = false;
clearTimeout(timeout);
}
var scheduleDrain;
var i = -1;
var len = types.length;
while (++ i < len) {
if (types[i] && types[i].test && types[i].test()) {
scheduleDrain = types[i].install(nextTick);
break;
}
}
module.exports = immediate;
function immediate(task) {
if (queue.push(task) === 1 && !draining) {
scheduleDrain();
}
}
},{"17":17,"18":18,"19":19,"2":2,"20":20}],17:[function(_dereq_,module,exports){
(function (global){
'use strict';
exports.test = function () {
if (global.setImmediate) {
// we can only get here in IE10
// which doesn't handel postMessage well
return false;
}
return typeof global.MessageChannel !== 'undefined';
};
exports.install = function (func) {
var channel = new global.MessageChannel();
channel.port1.onmessage = func;
return function () {
channel.port2.postMessage(0);
};
};
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],18:[function(_dereq_,module,exports){
(function (global){
'use strict';
//based off rsvp https://github.com/tildeio/rsvp.js
//license https://github.com/tildeio/rsvp.js/blob/master/LICENSE
//https://github.com/tildeio/rsvp.js/blob/master/lib/rsvp/asap.js
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
var Mutation = global.MutationObserver || global.WebKitMutationObserver;
function noop() {}
exports.test = function () {
return Mutation;
};
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
exports.install = function (handle) {
var called = 0;
var observer = new Mutation(handle);
var element = global.document.createTextNode('');
observer.observe(element, {
characterData: true
});
return function () {
element.data = (called = ++called % 2);
};
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],19:[function(_dereq_,module,exports){
(function (global){
'use strict';
exports.test = function () {
return 'document' in global && 'onreadystatechange' in global.document.createElement('script');
// TODO(shtylman)
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
exports.install = function (handle) {
return function () {
// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
var scriptEl = global.document.createElement('script');
scriptEl.onreadystatechange = function () {
handle();
scriptEl.onreadystatechange = null;
scriptEl.parentNode.removeChild(scriptEl);
scriptEl = null;
};
global.document.documentElement.appendChild(scriptEl);
return handle;
};
};
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],20:[function(_dereq_,module,exports){
},{}],22:[function(_dereq_,module,exports){
'use strict';
exports.test = function () {
return true;
};
exports.install = function (t) {
return function () {
setTimeout(t, 0);
};
};
},{}],21:[function(_dereq_,module,exports){
'use strict';
/* jshint -W079 */
var Blob = _dereq_(1);
var Promise = _dereq_(3);
var Promise = _dereq_(20);

@@ -772,5 +864,7 @@ //

* 'Anonymous' to avoid "tainted canvas" errors
* @param {number|undefined} quality - a number between 0 and 1 indicating image quality
* if the requested type is 'image/jpeg' or 'image/webp'
* @returns {Promise} Promise that resolves with the data URL string
*/
function imgSrcToDataURL(src, type, crossOrigin) {
function imgSrcToDataURL(src, type, crossOrigin, quality) {
type = type || 'image/png';

@@ -781,3 +875,3 @@

}).then(function (canvas) {
return canvas.toDataURL(type);
return canvas.toDataURL(type, quality);
});

@@ -790,12 +884,14 @@ }

* @param {string|undefined} type - the content type (optional, defaults to 'image/png')
* @param {number|undefined} quality - a number between 0 and 1 indicating image quality
* if the requested type is 'image/jpeg' or 'image/webp'
* @returns {Promise} Promise that resolves with the <code>Blob</code>
*/
function canvasToBlob(canvas, type) {
function canvasToBlob(canvas, type, quality) {
return Promise.resolve().then(function () {
if (typeof canvas.toBlob === 'function') {
return new Promise(function (resolve) {
canvas.toBlob(resolve, type);
canvas.toBlob(resolve, type, quality);
});
}
return dataURLToBlob(canvas.toDataURL(type));
return dataURLToBlob(canvas.toDataURL(type, quality));
});

@@ -815,5 +911,7 @@ }

* 'Anonymous' to avoid "tainted canvas" errors
* @param {number|undefined} quality - a number between 0 and 1 indicating image quality
* if the requested type is 'image/jpeg' or 'image/webp'
* @returns {Promise} Promise that resolves with the <code>Blob</code>
*/
function imgSrcToBlob(src, type, crossOrigin) {
function imgSrcToBlob(src, type, crossOrigin, quality) {
type = type || 'image/png';

@@ -824,3 +922,3 @@

}).then(function (canvas) {
return canvasToBlob(canvas, type);
return canvasToBlob(canvas, type, quality);
});

@@ -875,3 +973,3 @@ }

},{"1":1,"3":3}]},{},[21])(21)
});
},{"1":1,"20":20}]},{},[22])(22)
});

@@ -1,1 +0,1 @@

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.blobUtil=e()}}(function(){return function e(t,n,r){function o(u,f){if(!n[u]){if(!t[u]){var c="function"==typeof require&&require;if(!f&&c)return c(u,!0);if(i)return i(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var s=n[u]={exports:{}};t[u][0].call(s.exports,function(e){var n=t[u][1][e];return o(n?n:e)},s,s.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,t,n){(function(e){function n(e){for(var t=0;t<e.length;t++){var n=e[t];if(n.buffer instanceof ArrayBuffer){var r=n.buffer;if(n.byteLength!==r.byteLength){var o=new Uint8Array(n.byteLength);o.set(new Uint8Array(r,n.byteOffset,n.byteLength)),r=o.buffer}e[t]=r}}}function r(e,t){t=t||{};var r=new i;n(e);for(var o=0;o<e.length;o++)r.append(e[o]);return t.type?r.getBlob(t.type):r.getBlob()}function o(e,t){return n(e),new Blob(e,t||{})}var i=e.BlobBuilder||e.WebKitBlobBuilder||e.MSBlobBuilder||e.MozBlobBuilder,u=function(){try{var e=new Blob(["hi"]);return 2===e.size}catch(t){return!1}}(),f=u&&function(){try{var e=new Blob([new Uint8Array([1,2])]);return 2===e.size}catch(t){return!1}}(),c=i&&i.prototype.append&&i.prototype.getBlob;t.exports=function(){return u?f?e.Blob:o:c?r:void 0}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(e,t,n){},{}],3:[function(e,t,n){(function(n){"function"==typeof n.Promise?t.exports=n.Promise:t.exports=e(7)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{7:7}],4:[function(e,t,n){"use strict";function r(){}t.exports=r},{}],5:[function(e,t,n){"use strict";var r=e(8),o=e(10),i=e(11),u=e(4),f=e(6),c=o(new TypeError("must be an array"));t.exports=function(e){function t(e,t){function r(e){a[t]=e,++s===n&!o&&(o=!0,f.resolve(d,a))}i(e).then(r,function(e){o||(o=!0,f.reject(d,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return c;var n=e.length,o=!1;if(!n)return i([]);for(var a=new Array(n),s=0,l=-1,d=new r(u);++l<n;)t(e[l],l);return d}},{10:10,11:11,4:4,6:6,8:8}],6:[function(e,t,n){"use strict";function r(e){var t=e&&e.then;return e&&"object"==typeof e&&"function"==typeof t?function(){t.apply(e,arguments)}:void 0}var o=e(14),i=e(12),u=e(13);n.resolve=function(e,t){var f=o(r,t);if("error"===f.status)return n.reject(e,f.value);var c=f.value;if(c)i.safely(e,c);else{e.state=u.FULFILLED,e.outcome=t;for(var a=-1,s=e.queue.length;++a<s;)e.queue[a].callFulfilled(t)}return e},n.reject=function(e,t){e.state=u.REJECTED,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e}},{12:12,13:13,14:14}],7:[function(e,t,n){t.exports=n=e(8),n.resolve=e(11),n.reject=e(10),n.all=e(5)},{10:10,11:11,5:5,8:8}],8:[function(e,t,n){"use strict";function r(e){if(!(this instanceof r))return new r(e);if("function"!=typeof e)throw new TypeError("reslover must be a function");this.state=f.PENDING,this.queue=[],this.outcome=void 0,e!==i&&u.safely(this,e)}var o=e(15),i=e(4),u=e(12),f=e(13),c=e(9);t.exports=r,r.prototype["catch"]=function(e){return this.then(null,e)},r.prototype.then=function(e,t){if("function"!=typeof e&&this.state===f.FULFILLED||"function"!=typeof t&&this.state===f.REJECTED)return this;var n=new r(i);if(this.state!==f.PENDING){var u=this.state===f.FULFILLED?e:t;o(n,u,this.outcome)}else this.queue.push(new c(n,e,t));return n}},{12:12,13:13,15:15,4:4,9:9}],9:[function(e,t,n){"use strict";function r(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}var o=e(6),i=e(15);t.exports=r,r.prototype.callFulfilled=function(e){o.resolve(this.promise,e)},r.prototype.otherCallFulfilled=function(e){i(this.promise,this.onFulfilled,e)},r.prototype.callRejected=function(e){o.reject(this.promise,e)},r.prototype.otherCallRejected=function(e){i(this.promise,this.onRejected,e)}},{15:15,6:6}],10:[function(e,t,n){"use strict";function r(e){var t=new o(i);return u.reject(t,e)}var o=e(8),i=e(4),u=e(6);t.exports=r},{4:4,6:6,8:8}],11:[function(e,t,n){"use strict";function r(e){if(e)return e instanceof o?e:u.resolve(new o(i),e);var t=typeof e;switch(t){case"boolean":return f;case"undefined":return a;case"object":return c;case"number":return s;case"string":return l}}var o=e(8),i=e(4),u=e(6);t.exports=r;var f=u.resolve(new o(i),!1),c=u.resolve(new o(i),null),a=u.resolve(new o(i),void 0),s=u.resolve(new o(i),0),l=u.resolve(new o(i),"")},{4:4,6:6,8:8}],12:[function(e,t,n){"use strict";function r(e,t){function n(t){f||(f=!0,o.reject(e,t))}function r(t){f||(f=!0,o.resolve(e,t))}function u(){t(r,n)}var f=!1,c=i(u);"error"===c.status&&n(c.value)}var o=e(6),i=e(14);n.safely=r},{14:14,6:6}],13:[function(e,t,n){n.REJECTED=["REJECTED"],n.FULFILLED=["FULFILLED"],n.PENDING=["PENDING"]},{}],14:[function(e,t,n){"use strict";function r(e,t){var n={};try{n.value=e(t),n.status="success"}catch(r){n.status="error",n.value=r}return n}t.exports=r},{}],15:[function(e,t,n){"use strict";function r(e,t,n){o(function(){var r;try{r=t(n)}catch(o){return i.reject(e,o)}r===e?i.reject(e,new TypeError("Cannot resolve promise with itself")):i.resolve(e,r)})}var o=e(16),i=e(6);t.exports=r},{16:16,6:6}],16:[function(e,t,n){"use strict";function r(){u=!1,f&&f.length?l=f.concat(l):s=-1,l.length&&o()}function o(){u=!0;for(var e=l.length,t=setTimeout(r);e;){for(f=l,l=[];++s<e;)f[s]();s=-1,e=l.length}s=-1,u=!1,clearTimeout(t)}function i(e){1!==l.push(e)||u||c()}for(var u,f,c,a=[e(2),e(18),e(17),e(19),e(20)],s=-1,l=[],d=-1,p=a.length;++d<p;)if(a[d]&&a[d].test&&a[d].test()){c=a[d].install(o);break}t.exports=i},{17:17,18:18,19:19,2:2,20:20}],17:[function(e,t,n){(function(e){"use strict";n.test=function(){return e.setImmediate?!1:"undefined"!=typeof e.MessageChannel},n.install=function(t){var n=new e.MessageChannel;return n.port1.onmessage=t,function(){n.port2.postMessage(0)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],18:[function(e,t,n){(function(e){"use strict";var t=e.MutationObserver||e.WebKitMutationObserver;n.test=function(){return t},n.install=function(n){var r=0,o=new t(n),i=e.document.createTextNode("");return o.observe(i,{characterData:!0}),function(){i.data=r=++r%2}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],19:[function(e,t,n){(function(e){"use strict";n.test=function(){return"document"in e&&"onreadystatechange"in e.document.createElement("script")},n.install=function(t){return function(){var n=e.document.createElement("script");return n.onreadystatechange=function(){t(),n.onreadystatechange=null,n.parentNode.removeChild(n),n=null},e.document.documentElement.appendChild(n),t}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],20:[function(e,t,n){"use strict";n.test=function(){return!0},n.install=function(e){return function(){setTimeout(e,0)}}},{}],21:[function(e,t,n){"use strict";function r(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),o=-1;++o<t;)r[o]=e.charCodeAt(o);return n}function o(e){for(var t="",n=new Uint8Array(e),r=n.byteLength,o=-1;++o<r;)t+=String.fromCharCode(n[o]);return t}function i(e,t){return new B(function(n,r){var o=new Image;t&&(o.crossOrigin=t),o.onload=function(){n(o)},o.onerror=r,o.src=e})}function u(e){var t=document.createElement("canvas");t.width=e.width,t.height=e.height;var n=t.getContext("2d");return n.drawImage(e,0,0,e.width,e.height,0,0,e.width,e.height),t}function f(e,t){return t=t||{},"string"==typeof t&&(t={type:t}),new m(e,t)}function c(e){return(window.URL||window.webkitURL).createObjectURL(e)}function a(e){return(window.URL||window.webkitURL).revokeObjectURL(e)}function s(e){return new B(function(t,n){var r=new FileReader,i="function"==typeof r.readAsBinaryString;r.onloadend=function(e){var n=e.target.result||"";return i?t(n):void t(o(n))},r.onerror=n,i?r.readAsBinaryString(e):r.readAsArrayBuffer(e)})}function l(e,t){return B.resolve().then(function(){var n=[r(atob(e))];return t?f(n,{type:t}):f(n)})}function d(e,t){return B.resolve().then(function(){return l(btoa(e),t)})}function p(e){return s(e).then(function(e){return btoa(e)})}function h(e){return B.resolve().then(function(){var t=e.match(/data:([^;]+)/)[1],n=e.replace(/^[^,]+,/,""),o=r(atob(n));return f([o],{type:t})})}function v(e,t,n){return t=t||"image/png",i(e,n).then(function(e){return u(e)}).then(function(e){return e.toDataURL(t)})}function y(e,t){return B.resolve().then(function(){return"function"==typeof e.toBlob?new B(function(n){e.toBlob(n,t)}):h(e.toDataURL(t))})}function w(e,t,n){return t=t||"image/png",i(e,n).then(function(e){return u(e)}).then(function(e){return y(e,t)})}function b(e,t){return B.resolve().then(function(){return f([e],t)})}function g(e){return new B(function(t,n){var r=new FileReader;r.onloadend=function(e){var n=e.target.result||new ArrayBuffer(0);t(n)},r.onerror=n,r.readAsArrayBuffer(e)})}var m=e(1),B=e(3);t.exports={createBlob:f,createObjectURL:c,revokeObjectURL:a,imgSrcToBlob:w,imgSrcToDataURL:v,canvasToBlob:y,dataURLToBlob:h,blobToBase64String:p,base64StringToBlob:l,binaryStringToBlob:d,blobToBinaryString:s,arrayBufferToBlob:b,blobToArrayBuffer:g}},{1:1,3:3}]},{},[21])(21)});
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.blobUtil=e()}}(function(){return function e(t,n,r){function o(u,f){if(!n[u]){if(!t[u]){var c="function"==typeof require&&require;if(!f&&c)return c(u,!0);if(i)return i(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var s=n[u]={exports:{}};t[u][0].call(s.exports,function(e){var n=t[u][1][e];return o(n?n:e)},s,s.exports,e,t,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({1:[function(e,t,n){(function(e){function n(e){for(var t=0;t<e.length;t++){var n=e[t];if(n.buffer instanceof ArrayBuffer){var r=n.buffer;if(n.byteLength!==r.byteLength){var o=new Uint8Array(n.byteLength);o.set(new Uint8Array(r,n.byteOffset,n.byteLength)),r=o.buffer}e[t]=r}}}function r(e,t){t=t||{};var r=new i;n(e);for(var o=0;o<e.length;o++)r.append(e[o]);return t.type?r.getBlob(t.type):r.getBlob()}function o(e,t){return n(e),new Blob(e,t||{})}var i=e.BlobBuilder||e.WebKitBlobBuilder||e.MSBlobBuilder||e.MozBlobBuilder,u=function(){try{var e=new Blob(["hi"]);return 2===e.size}catch(t){return!1}}(),f=u&&function(){try{var e=new Blob([new Uint8Array([1,2])]);return 2===e.size}catch(t){return!1}}(),c=i&&i.prototype.append&&i.prototype.getBlob;t.exports=function(){return u?f?e.Blob:o:c?r:void 0}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(e,t,n){"use strict";function r(){f=!1,c&&c.length?d=c.concat(d):l=-1,d.length&&o()}function o(){p=!1,f=!0;for(var e=d.length,t=setTimeout(r);e;){for(c=d,d=[];++l<e;)c[l].run();l=-1,e=d.length}l=-1,f=!1,clearTimeout(t)}function i(e,t){this.fun=e,this.array=t}function u(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];d.push(new i(e,t)),p||f||(p=!0,a())}for(var f,c,a,s=[e(5),e(4),e(3),e(6),e(7)],l=-1,d=[],p=!1,h=-1,v=s.length;++h<v;)if(s[h]&&s[h].test&&s[h].test()){a=s[h].install(o);break}i.prototype.run=function(){this.fun.apply(null,this.array)},t.exports=u},{3:3,4:4,5:5,6:6,7:7}],3:[function(e,t,n){(function(e){"use strict";n.test=function(){return e.setImmediate?!1:"undefined"!=typeof e.MessageChannel},n.install=function(t){var n=new e.MessageChannel;return n.port1.onmessage=t,function(){n.port2.postMessage(0)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,t,n){(function(e){"use strict";var t=e.MutationObserver||e.WebKitMutationObserver;n.test=function(){return t},n.install=function(n){var r=0,o=new t(n),i=e.document.createTextNode("");return o.observe(i,{characterData:!0}),function(){i.data=r=++r%2}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[function(e,t,n){(function(e){"use strict";n.test=function(){return"undefined"!=typeof e&&!e.browser},n.install=function(t){return function(){e.nextTick(t)}}}).call(this,e(21))},{21:21}],6:[function(e,t,n){(function(e){"use strict";n.test=function(){return"document"in e&&"onreadystatechange"in e.document.createElement("script")},n.install=function(t){return function(){var n=e.document.createElement("script");return n.onreadystatechange=function(){t(),n.onreadystatechange=null,n.parentNode.removeChild(n),n=null},e.document.documentElement.appendChild(n),t}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],7:[function(e,t,n){"use strict";n.test=function(){return!0},n.install=function(e){return function(){setTimeout(e,0)}}},{}],8:[function(e,t,n){"use strict";function r(){}t.exports=r},{}],9:[function(e,t,n){"use strict";var r=e(12),o=e(14),i=e(15),u=e(8),f=e(10),c=o(new TypeError("must be an array"));t.exports=function(e){function t(e,t){function r(e){a[t]=e,++s===n&!o&&(o=!0,f.resolve(d,a))}i(e).then(r,function(e){o||(o=!0,f.reject(d,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return c;var n=e.length,o=!1;if(!n)return i([]);for(var a=new Array(n),s=0,l=-1,d=new r(u);++l<n;)t(e[l],l);return d}},{10:10,12:12,14:14,15:15,8:8}],10:[function(e,t,n){"use strict";function r(e){var t=e&&e.then;return e&&"object"==typeof e&&"function"==typeof t?function(){t.apply(e,arguments)}:void 0}var o=e(18),i=e(16),u=e(17);n.resolve=function(e,t){var f=o(r,t);if("error"===f.status)return n.reject(e,f.value);var c=f.value;if(c)i.safely(e,c);else{e.state=u.FULFILLED,e.outcome=t;for(var a=-1,s=e.queue.length;++a<s;)e.queue[a].callFulfilled(t)}return e},n.reject=function(e,t){e.state=u.REJECTED,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e}},{16:16,17:17,18:18}],11:[function(e,t,n){t.exports=n=e(12),n.resolve=e(15),n.reject=e(14),n.all=e(9)},{12:12,14:14,15:15,9:9}],12:[function(e,t,n){"use strict";function r(e){if(!(this instanceof r))return new r(e);if("function"!=typeof e)throw new TypeError("reslover must be a function");this.state=f.PENDING,this.queue=[],this.outcome=void 0,e!==i&&u.safely(this,e)}var o=e(19),i=e(8),u=e(16),f=e(17),c=e(13);t.exports=r,r.prototype["catch"]=function(e){return this.then(null,e)},r.prototype.then=function(e,t){if("function"!=typeof e&&this.state===f.FULFILLED||"function"!=typeof t&&this.state===f.REJECTED)return this;var n=new r(i);if(this.state!==f.PENDING){var u=this.state===f.FULFILLED?e:t;o(n,u,this.outcome)}else this.queue.push(new c(n,e,t));return n}},{13:13,16:16,17:17,19:19,8:8}],13:[function(e,t,n){"use strict";function r(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}var o=e(10),i=e(19);t.exports=r,r.prototype.callFulfilled=function(e){o.resolve(this.promise,e)},r.prototype.otherCallFulfilled=function(e){i(this.promise,this.onFulfilled,e)},r.prototype.callRejected=function(e){o.reject(this.promise,e)},r.prototype.otherCallRejected=function(e){i(this.promise,this.onRejected,e)}},{10:10,19:19}],14:[function(e,t,n){"use strict";function r(e){var t=new o(i);return u.reject(t,e)}var o=e(12),i=e(8),u=e(10);t.exports=r},{10:10,12:12,8:8}],15:[function(e,t,n){"use strict";function r(e){if(e)return e instanceof o?e:u.resolve(new o(i),e);var t=typeof e;switch(t){case"boolean":return f;case"undefined":return a;case"object":return c;case"number":return s;case"string":return l}}var o=e(12),i=e(8),u=e(10);t.exports=r;var f=u.resolve(new o(i),!1),c=u.resolve(new o(i),null),a=u.resolve(new o(i),void 0),s=u.resolve(new o(i),0),l=u.resolve(new o(i),"")},{10:10,12:12,8:8}],16:[function(e,t,n){"use strict";function r(e,t){function n(t){f||(f=!0,o.reject(e,t))}function r(t){f||(f=!0,o.resolve(e,t))}function u(){t(r,n)}var f=!1,c=i(u);"error"===c.status&&n(c.value)}var o=e(10),i=e(18);n.safely=r},{10:10,18:18}],17:[function(e,t,n){n.REJECTED=["REJECTED"],n.FULFILLED=["FULFILLED"],n.PENDING=["PENDING"]},{}],18:[function(e,t,n){"use strict";function r(e,t){var n={};try{n.value=e(t),n.status="success"}catch(r){n.status="error",n.value=r}return n}t.exports=r},{}],19:[function(e,t,n){"use strict";function r(e,t,n){o(function(){var r;try{r=t(n)}catch(o){return i.reject(e,o)}r===e?i.reject(e,new TypeError("Cannot resolve promise with itself")):i.resolve(e,r)})}var o=e(2),i=e(10);t.exports=r},{10:10,2:2}],20:[function(e,t,n){(function(n){"function"==typeof n.Promise?t.exports=n.Promise:t.exports=e(11)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{11:11}],21:[function(e,t,n){function r(){if(!f){f=!0;for(var e,t=u.length;t;){e=u,u=[];for(var n=-1;++n<t;)e[n]();t=u.length}f=!1}}function o(){}var i=t.exports={},u=[],f=!1;i.nextTick=function(e){u.push(e),f||setTimeout(r,0)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=o,i.addListener=o,i.once=o,i.off=o,i.removeListener=o,i.removeAllListeners=o,i.emit=o,i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}],22:[function(e,t,n){"use strict";function r(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),o=-1;++o<t;)r[o]=e.charCodeAt(o);return n}function o(e){for(var t="",n=new Uint8Array(e),r=n.byteLength,o=-1;++o<r;)t+=String.fromCharCode(n[o]);return t}function i(e,t){return new L(function(n,r){var o=new Image;t&&(o.crossOrigin=t),o.onload=function(){n(o)},o.onerror=r,o.src=e})}function u(e){var t=document.createElement("canvas");t.width=e.width,t.height=e.height;var n=t.getContext("2d");return n.drawImage(e,0,0,e.width,e.height,0,0,e.width,e.height),t}function f(e,t){return t=t||{},"string"==typeof t&&(t={type:t}),new m(e,t)}function c(e){return(window.URL||window.webkitURL).createObjectURL(e)}function a(e){return(window.URL||window.webkitURL).revokeObjectURL(e)}function s(e){return new L(function(t,n){var r=new FileReader,i="function"==typeof r.readAsBinaryString;r.onloadend=function(e){var n=e.target.result||"";return i?t(n):void t(o(n))},r.onerror=n,i?r.readAsBinaryString(e):r.readAsArrayBuffer(e)})}function l(e,t){return L.resolve().then(function(){var n=[r(atob(e))];return t?f(n,{type:t}):f(n)})}function d(e,t){return L.resolve().then(function(){return l(btoa(e),t)})}function p(e){return s(e).then(function(e){return btoa(e)})}function h(e){return L.resolve().then(function(){var t=e.match(/data:([^;]+)/)[1],n=e.replace(/^[^,]+,/,""),o=r(atob(n));return f([o],{type:t})})}function v(e,t,n,r){return t=t||"image/png",i(e,n).then(function(e){return u(e)}).then(function(e){return e.toDataURL(t,r)})}function y(e,t,n){return L.resolve().then(function(){return"function"==typeof e.toBlob?new L(function(r){e.toBlob(r,t,n)}):h(e.toDataURL(t,n))})}function w(e,t,n,r){return t=t||"image/png",i(e,n).then(function(e){return u(e)}).then(function(e){return y(e,t,r)})}function b(e,t){return L.resolve().then(function(){return f([e],t)})}function g(e){return new L(function(t,n){var r=new FileReader;r.onloadend=function(e){var n=e.target.result||new ArrayBuffer(0);t(n)},r.onerror=n,r.readAsArrayBuffer(e)})}var m=e(1),L=e(20);t.exports={createBlob:f,createObjectURL:c,revokeObjectURL:a,imgSrcToBlob:w,imgSrcToDataURL:v,canvasToBlob:y,dataURLToBlob:h,blobToBase64String:p,base64StringToBlob:l,binaryStringToBlob:d,blobToBinaryString:s,arrayBufferToBlob:b,blobToArrayBuffer:g}},{1:1,20:20}]},{},[22])(22)});

@@ -207,5 +207,7 @@ 'use strict';

* 'Anonymous' to avoid "tainted canvas" errors
* @param {number|undefined} quality - a number between 0 and 1 indicating image quality
* if the requested type is 'image/jpeg' or 'image/webp'
* @returns {Promise} Promise that resolves with the data URL string
*/
function imgSrcToDataURL(src, type, crossOrigin) {
function imgSrcToDataURL(src, type, crossOrigin, quality) {
type = type || 'image/png';

@@ -216,3 +218,3 @@

}).then(function (canvas) {
return canvas.toDataURL(type);
return canvas.toDataURL(type, quality);
});

@@ -225,12 +227,14 @@ }

* @param {string|undefined} type - the content type (optional, defaults to 'image/png')
* @param {number|undefined} quality - a number between 0 and 1 indicating image quality
* if the requested type is 'image/jpeg' or 'image/webp'
* @returns {Promise} Promise that resolves with the <code>Blob</code>
*/
function canvasToBlob(canvas, type) {
function canvasToBlob(canvas, type, quality) {
return Promise.resolve().then(function () {
if (typeof canvas.toBlob === 'function') {
return new Promise(function (resolve) {
canvas.toBlob(resolve, type);
canvas.toBlob(resolve, type, quality);
});
}
return dataURLToBlob(canvas.toDataURL(type));
return dataURLToBlob(canvas.toDataURL(type, quality));
});

@@ -250,5 +254,7 @@ }

* 'Anonymous' to avoid "tainted canvas" errors
* @param {number|undefined} quality - a number between 0 and 1 indicating image quality
* if the requested type is 'image/jpeg' or 'image/webp'
* @returns {Promise} Promise that resolves with the <code>Blob</code>
*/
function imgSrcToBlob(src, type, crossOrigin) {
function imgSrcToBlob(src, type, crossOrigin, quality) {
type = type || 'image/png';

@@ -259,3 +265,3 @@

}).then(function (canvas) {
return canvasToBlob(canvas, type);
return canvasToBlob(canvas, type, quality);
});

@@ -262,0 +268,0 @@ }

{
"name": "blob-util",
"version": "1.1.2",
"version": "1.2.0",
"description": "Utilities for working with Blob objects in the browser",

@@ -18,3 +18,3 @@ "main": "lib/index.js",

"author": "Nolan Lawson <nolan.lawson@gmail.com>",
"license": "Apache",
"license": "Apache-2.0",
"bugs": {

@@ -21,0 +21,0 @@ "url": "https://github.com/nolanlawson/blob-util/issues"

@@ -8,3 +8,3 @@ blob-util

It offers a tiny (~4KB min+gz) set of cross-browser utilities for translating Blobs to and from different formats:
It offers a tiny (~3.5KB min+gz) set of cross-browser utilities for translating Blobs to and from different formats:

@@ -71,2 +71,4 @@ * `<img/>` tags

A [File](https://developer.mozilla.org/en-US/docs/Web/API/File) is also a Blob. So if you have an `<input type="file">` in your page, you can let your users upload any file and then work with it as a Blob.
### Example

@@ -123,5 +125,5 @@

* [dataURLToBlob(dataURL)](#dataURLToBlob)
* [imgSrcToDataURL(src, type, crossOrigin)](#imgSrcToDataURL)
* [canvasToBlob(canvas, type)](#canvasToBlob)
* [imgSrcToBlob(src, type, crossOrigin)](#imgSrcToBlob)
* [imgSrcToDataURL(src, type, crossOrigin, quality)](#imgSrcToDataURL)
* [canvasToBlob(canvas, type, quality)](#canvasToBlob)
* [imgSrcToBlob(src, type, crossOrigin, quality)](#imgSrcToBlob)
* [arrayBufferToBlob(buffer, type)](#arrayBufferToBlob)

@@ -292,3 +294,3 @@ * [blobToArrayBuffer(blob)](#blobToArrayBuffer)

<a name="imgSrcToDataURL"></a>
###imgSrcToDataURL(src, type, crossOrigin)
###imgSrcToDataURL(src, type, crossOrigin, quality)
Convert an image's <code>src</code> URL to a data URL by loading the image and painting

@@ -306,2 +308,4 @@ it to a <code>canvas</code>. Returns a Promise.

'Anonymous' to avoid "tainted canvas" errors
- quality `number` | `undefined` - a number between 0 and 1 indicating image quality
if the requested type is 'image/jpeg' or 'image/webp'

@@ -330,3 +334,3 @@ **Returns**: `Promise` - Promise that resolves with the data URL string

<a name="canvasToBlob"></a>
###canvasToBlob(canvas, type)
###canvasToBlob(canvas, type, quality)
Convert a <code>canvas</code> to a <code>Blob</code>. Returns a Promise.

@@ -338,2 +342,4 @@

- type `string` | `undefined` - the content type (optional, defaults to 'image/png')
- quality `number` | `undefined` - a number between 0 and 1 indicating image quality
if the requested type is 'image/jpeg' or 'image/webp'

@@ -365,3 +371,3 @@ **Returns**: `Promise` - Promise that resolves with the <code>Blob</code>

<a name="imgSrcToBlob"></a>
###imgSrcToBlob(src, type, crossOrigin)
###imgSrcToBlob(src, type, crossOrigin, quality)
Convert an image's <code>src</code> URL to a <code>Blob</code> by loading the image and painting

@@ -379,2 +385,4 @@ it to a <code>canvas</code>. Returns a Promise.

'Anonymous' to avoid "tainted canvas" errors
- quality `number` | `undefined` - a number between 0 and 1 indicating image quality
if the requested type is 'image/jpeg' or 'image/webp'

@@ -381,0 +389,0 @@ **Returns**: `Promise` - Promise that resolves with the <code>Blob</code>

@@ -157,3 +157,12 @@ /*jshint expr:true */

});
it('convert with specific quality', function () {
var img = document.getElementById('kirby');
return blobUtil.imgSrcToBlob(img.src, 'image/jpeg', undefined, 1).then(function (blob) {
return blobUtil.imgSrcToBlob(img.src, 'image/jpeg', undefined, 0.5).then(function (lowQualityBlob) {
lowQualityBlob.size.should.be.lessThan(blob.size);
});
});
});
});
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc