blueimp-canvas-to-blob
Advanced tools
Comparing version 3.14.0 to 3.15.0
@@ -15,5 +15,5 @@ /* | ||
/* global atob, Blob, define */ | ||
/* global define, Uint8Array, ArrayBuffer, module */ | ||
;(function (window) { | ||
;(function(window) { | ||
'use strict' | ||
@@ -25,3 +25,3 @@ | ||
window.Blob && | ||
(function () { | ||
(function() { | ||
try { | ||
@@ -36,3 +36,3 @@ return Boolean(new Blob()) | ||
window.Uint8Array && | ||
(function () { | ||
(function() { | ||
try { | ||
@@ -55,3 +55,3 @@ return new Blob([new Uint8Array(100)]).size === 100 | ||
window.Uint8Array && | ||
function (dataURI) { | ||
function(dataURI) { | ||
var matches, | ||
@@ -102,5 +102,5 @@ mediaType, | ||
if (CanvasPrototype.mozGetAsFile) { | ||
CanvasPrototype.toBlob = function (callback, type, quality) { | ||
CanvasPrototype.toBlob = function(callback, type, quality) { | ||
var self = this | ||
setTimeout(function () { | ||
setTimeout(function() { | ||
if (quality && CanvasPrototype.toDataURL && dataURLtoBlob) { | ||
@@ -114,5 +114,5 @@ callback(dataURLtoBlob(self.toDataURL(type, quality))) | ||
} else if (CanvasPrototype.toDataURL && dataURLtoBlob) { | ||
CanvasPrototype.toBlob = function (callback, type, quality) { | ||
CanvasPrototype.toBlob = function(callback, type, quality) { | ||
var self = this | ||
setTimeout(function () { | ||
setTimeout(function() { | ||
callback(dataURLtoBlob(self.toDataURL(type, quality))) | ||
@@ -124,3 +124,3 @@ }) | ||
if (typeof define === 'function' && define.amd) { | ||
define(function () { | ||
define(function() { | ||
return dataURLtoBlob | ||
@@ -127,0 +127,0 @@ }) |
@@ -1,2 +0,2 @@ | ||
!function(t){"use strict";var e=t.HTMLCanvasElement&&t.HTMLCanvasElement.prototype,o=t.Blob&&function(){try{return Boolean(new Blob)}catch(t){return!1}}(),n=o&&t.Uint8Array&&function(){try{return 100===new Blob([new Uint8Array(100)]).size}catch(t){return!1}}(),r=t.BlobBuilder||t.WebKitBlobBuilder||t.MozBlobBuilder||t.MSBlobBuilder,a=/^data:((.*?)(;charset=.*?)?)(;base64)?,/,i=(o||r)&&t.atob&&t.ArrayBuffer&&t.Uint8Array&&function(t){var e,i,l,u,c,f,b,d,B;if(!(e=t.match(a)))throw new Error("invalid data URI");for(i=e[2]?e[1]:"text/plain"+(e[3]||";charset=US-ASCII"),l=!!e[4],u=t.slice(e[0].length),c=l?atob(u):decodeURIComponent(u),f=new ArrayBuffer(c.length),b=new Uint8Array(f),d=0;d<c.length;d+=1)b[d]=c.charCodeAt(d);return o?new Blob([n?b:f],{type:i}):((B=new r).append(f),B.getBlob(i))};t.HTMLCanvasElement&&!e.toBlob&&(e.mozGetAsFile?e.toBlob=function(t,o,n){var r=this;setTimeout(function(){t(n&&e.toDataURL&&i?i(r.toDataURL(o,n)):r.mozGetAsFile("blob",o))})}:e.toDataURL&&i&&(e.toBlob=function(t,e,o){var n=this;setTimeout(function(){t(i(n.toDataURL(e,o)))})})),"function"==typeof define&&define.amd?define(function(){return i}):"object"==typeof module&&module.exports?module.exports=i:t.dataURLtoBlob=i}(window); | ||
!function(t){"use strict";var r=t.HTMLCanvasElement&&t.HTMLCanvasElement.prototype,f=t.Blob&&function(){try{return Boolean(new Blob)}catch(t){return!1}}(),b=f&&t.Uint8Array&&function(){try{return 100===new Blob([new Uint8Array(100)]).size}catch(t){return!1}}(),d=t.BlobBuilder||t.WebKitBlobBuilder||t.MozBlobBuilder||t.MSBlobBuilder,B=/^data:((.*?)(;charset=.*?)?)(;base64)?,/,a=(f||d)&&t.atob&&t.ArrayBuffer&&t.Uint8Array&&function(t){var e,o,n,r,a,i,l,u,c;if(!(e=t.match(B)))throw new Error("invalid data URI");for(o=e[2]?e[1]:"text/plain"+(e[3]||";charset=US-ASCII"),n=!!e[4],r=t.slice(e[0].length),a=n?atob(r):decodeURIComponent(r),i=new ArrayBuffer(a.length),l=new Uint8Array(i),u=0;u<a.length;u+=1)l[u]=a.charCodeAt(u);return f?new Blob([b?l:i],{type:o}):((c=new d).append(i),c.getBlob(o))};t.HTMLCanvasElement&&!r.toBlob&&(r.mozGetAsFile?r.toBlob=function(t,e,o){var n=this;setTimeout(function(){o&&r.toDataURL&&a?t(a(n.toDataURL(e,o))):t(n.mozGetAsFile("blob",e))})}:r.toDataURL&&a&&(r.toBlob=function(t,e,o){var n=this;setTimeout(function(){t(a(n.toDataURL(e,o)))})})),"function"==typeof define&&define.amd?define(function(){return a}):"object"==typeof module&&module.exports?module.exports=a:t.dataURLtoBlob=a}(window); | ||
//# sourceMappingURL=canvas-to-blob.min.js.map |
@@ -5,8 +5,8 @@ MIT License | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
@@ -17,7 +17,6 @@ The above copyright notice and this permission notice shall be included in all | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
{ | ||
"name": "blueimp-canvas-to-blob", | ||
"version": "3.14.0", | ||
"version": "3.15.0", | ||
"title": "JavaScript Canvas to Blob", | ||
@@ -23,19 +23,35 @@ "description": "Canvas to Blob is a polyfill for the standard JavaScript canvas.toBlob method. It can be used to create Blob objects from an HTML canvas element.", | ||
"license": "MIT", | ||
"main": "./js/canvas-to-blob.js", | ||
"devDependencies": { | ||
"concurrently": "^3.5.0", | ||
"eslint": "^4.5.0", | ||
"eslint-config-standard": "^10.2.1", | ||
"eslint-plugin-import": "^2.7.0", | ||
"eslint-plugin-node": "^5.1.1", | ||
"eslint-plugin-promise": "^3.5.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"get-port-cli": "^1.1.0", | ||
"http-server": "^0.10.0", | ||
"mocha-chrome": "^0.1.1", | ||
"prettier-eslint-cli": "^4.2.1", | ||
"uglify-js": "^3.0.28" | ||
"concurrently": "4", | ||
"eslint": "6", | ||
"eslint-config-blueimp": "1", | ||
"eslint-config-prettier": "6", | ||
"eslint-plugin-jsdoc": "15", | ||
"eslint-plugin-prettier": "3", | ||
"prettier": "1", | ||
"get-port-cli": "2", | ||
"http-server": "0", | ||
"mocha-chrome": "2", | ||
"uglify-js": "3" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"blueimp", | ||
"plugin:jsdoc/recommended", | ||
"plugin:prettier/recommended" | ||
], | ||
"env": { | ||
"browser": true | ||
} | ||
}, | ||
"eslintIgnore": [ | ||
"js/*.min.js", | ||
"test/vendor" | ||
], | ||
"prettier": { | ||
"proseWrap": "always", | ||
"semi": false, | ||
"singleQuote": true | ||
}, | ||
"scripts": { | ||
"format": "prettier-eslint --no-semi --single-quote --write **/*.js", | ||
"lint": "eslint .", | ||
@@ -50,3 +66,8 @@ "serve": "http-server . -a 127.0.0.1 -p $PORT -s", | ||
"postversion": "git push --tags origin master master:gh-pages && npm publish" | ||
} | ||
}, | ||
"files": [ | ||
"js/*.js", | ||
"js/*.js.map" | ||
], | ||
"main": "./js/canvas-to-blob.js" | ||
} |
# JavaScript Canvas to Blob | ||
## Contents | ||
- [Description](#description) | ||
- [Usage](#usage) | ||
- [Requirements](#requirements) | ||
- [API](#api) | ||
- [Browsers](#browsers) | ||
- [Desktop browsers](#desktop-browsers) | ||
- [Mobile browsers](#mobile-browsers) | ||
- [Test](#test) | ||
- [License](#license) | ||
## Description | ||
Canvas to Blob is a polyfill for the standard JavaScript | ||
@@ -9,7 +22,7 @@ [canvas.toBlob](http://www.w3.org/TR/html5/scripting-1.html#dom-canvas-toblob) | ||
It can be used to create | ||
[Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) | ||
objects from an HTML | ||
[canvas](https://developer.mozilla.org/en-US/docs/HTML/Canvas) element. | ||
[Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) objects from an | ||
HTML [canvas](https://developer.mozilla.org/en-US/docs/HTML/Canvas) element. | ||
## Usage | ||
Include the (minified) JavaScript Canvas to Blob script in your HTML markup: | ||
@@ -21,19 +34,16 @@ | ||
Then use the *canvas.toBlob()* method in the same way as the native | ||
Then use the _canvas.toBlob()_ method in the same way as the native | ||
implementation: | ||
```js | ||
var canvas = document.createElement('canvas'); | ||
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' | ||
); | ||
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') | ||
} | ||
@@ -43,2 +53,3 @@ ``` | ||
## Requirements | ||
The JavaScript Canvas to Blob function has zero dependencies. | ||
@@ -51,2 +62,3 @@ | ||
## API | ||
In addition to the **canvas.toBlob** polyfill, the JavaScript Canvas to Blob | ||
@@ -59,10 +71,12 @@ script provides one additional function called **dataURLtoBlob**, which is added | ||
// 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); | ||
var b64Data = | ||
'R0lGODdhUAA8AIABAAAAAP///ywAAAAAUAA8AAACS4SPqcvtD6' + | ||
'OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofE' + | ||
'ovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5PKsAAA7', | ||
imageUrl = 'data:image/gif;base64,' + b64Data, | ||
blob = window.dataURLtoBlob && window.dataURLtoBlob(imageUrl) | ||
``` | ||
E.g. Via Npm/Browserify: | ||
```shell | ||
@@ -73,35 +87,42 @@ npm i blueimp-canvas-to-blob | ||
Requiring loads the dataURLtoBlob function. | ||
```js | ||
var dataURLtoBlob = require('blueimp-canvas-to-blob'); | ||
var dataURLtoBlob = require('blueimp-canvas-to-blob') | ||
// 80x60px GIF image (color black, base64 data): | ||
var b64Data = 'R0lGODdhUAA8AIABAAAAAP///ywAAAAAUAA8AAACS4SPqcvtD6' + | ||
'OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofE' + | ||
'ovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5PKsAAA7', | ||
imageUrl = 'data:image/gif;base64,' + b64Data, | ||
blob = dataURLtoBlob(imageURL); | ||
var b64Data = | ||
'R0lGODdhUAA8AIABAAAAAP///ywAAAAAUAA8AAACS4SPqcvtD6' + | ||
'OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofE' + | ||
'ovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5PKsAAA7', | ||
imageUrl = 'data:image/gif;base64,' + b64Data, | ||
blob = dataURLtoBlob(imageURL) | ||
``` | ||
## Browsers | ||
The following browsers support either the native or the polyfill | ||
*canvas.toBlob()* method: | ||
_canvas.toBlob()_ method: | ||
### Desktop browsers | ||
* Google Chrome (see [Chromium issue #67587](https://code.google.com/p/chromium/issues/detail?id=67587)) | ||
* Apple Safari 6.0+ (see [Mozilla issue #648610](https://bugzilla.mozilla.org/show_bug.cgi?id=648610)) | ||
* Mozilla Firefox 4.0+ | ||
* Microsoft Internet Explorer 10.0+ | ||
- Google Chrome (see | ||
[Chromium issue #67587](https://code.google.com/p/chromium/issues/detail?id=67587)) | ||
- Apple Safari 6.0+ (see | ||
[Mozilla issue #648610](https://bugzilla.mozilla.org/show_bug.cgi?id=648610)) | ||
- Mozilla Firefox 4.0+ | ||
- Microsoft Internet Explorer 10.0+ | ||
### Mobile browsers | ||
* Apple Safari Mobile on iOS 6.0+ | ||
* Google Chrome on iOS 6.0+ | ||
* Google Chrome on Android 4.0+ | ||
- Apple Safari Mobile on iOS 6.0+ | ||
- Google Chrome on iOS 6.0+ | ||
- Google Chrome on Android 4.0+ | ||
## Test | ||
[JavaScript Canvas to Blob Test](https://blueimp.github.io/JavaScript-Canvas-to-Blob/test/) | ||
## License | ||
The JavaScript Canvas to Blob script is released under the | ||
[MIT license](https://opensource.org/licenses/MIT). |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13388
11
123