blueimp-canvas-to-blob
Advanced tools
Comparing version 3.3.0 to 3.4.0
@@ -15,3 +15,3 @@ /* | ||
/*global window, atob, Blob, ArrayBuffer, Uint8Array, define, module */ | ||
/* global atob, Blob, define */ | ||
@@ -18,0 +18,0 @@ ;(function (window) { |
{ | ||
"name": "blueimp-canvas-to-blob", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"title": "JavaScript Canvas to Blob", | ||
@@ -25,8 +25,11 @@ "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.", | ||
"devDependencies": { | ||
"mocha-phantomjs": "4.0.1", | ||
"standard": "6.0.7", | ||
"uglify-js": "2.6.1" | ||
"phantomjs-prebuilt": "2.1.13", | ||
"mocha-phantomjs-core": "1.3.1", | ||
"standard": "8.3.0", | ||
"uglify-js": "2.7.3" | ||
}, | ||
"scripts": { | ||
"test": "standard js/*.js test/*.js && mocha-phantomjs test/index.html", | ||
"lint": "standard js/*.js test/*.js", | ||
"unit": "phantomjs node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/index.html", | ||
"test": "npm run lint && npm run unit", | ||
"build": "cd js && uglifyjs canvas-to-blob.js -c -m -o canvas-to-blob.min.js --source-map canvas-to-blob.min.js.map", | ||
@@ -33,0 +36,0 @@ "preversion": "npm test", |
@@ -12,3 +12,3 @@ /* | ||
/*global window, describe, it, Blob */ | ||
/* global describe, it, Blob */ | ||
@@ -30,3 +30,3 @@ ;(function (expect) { | ||
function (newBlob) { | ||
expect(newBlob).to.be.a(Blob) | ||
expect(newBlob).to.be.a.instanceOf(Blob) | ||
done() | ||
@@ -42,3 +42,3 @@ } | ||
function (newBlob) { | ||
expect(newBlob.type).to.be('image/png') | ||
expect(newBlob.type).to.equal('image/png') | ||
done() | ||
@@ -55,3 +55,3 @@ }, | ||
function (newBlob) { | ||
expect(newBlob.type).to.be('image/jpeg') | ||
expect(newBlob.type).to.equal('image/jpeg') | ||
done() | ||
@@ -69,4 +69,4 @@ }, | ||
window.loadImage(newBlob, function (img) { | ||
expect(img.width).to.be(canvas.width) | ||
expect(img.height).to.be(canvas.height) | ||
expect(img.width).to.equal(canvas.width) | ||
expect(img.height).to.equal(canvas.height) | ||
done() | ||
@@ -88,4 +88,4 @@ }) | ||
.getImageData(0, 0, newCanvas.width, newCanvas.height) | ||
expect(canvasData.width).to.be(newCanvasData.width) | ||
expect(canvasData.height).to.be(newCanvasData.height) | ||
expect(canvasData.width).to.equal(newCanvasData.width) | ||
expect(canvasData.height).to.equal(newCanvasData.height) | ||
done() | ||
@@ -98,2 +98,2 @@ }, {canvas: true}) | ||
}) | ||
}(this.expect)) | ||
}(this.chai.expect)) |
@@ -12,3 +12,3 @@ /* | ||
/*global define, module, window, document, URL, webkitURL, FileReader */ | ||
/* global define, URL, webkitURL, FileReader */ | ||
@@ -21,15 +21,11 @@ ;(function ($) { | ||
// element (if supported by the browser) as parameter: | ||
var loadImage = function (file, callback, options) { | ||
function loadImage (file, callback, options) { | ||
var img = document.createElement('img') | ||
var url | ||
var oUrl | ||
img.onerror = callback | ||
img.onload = function () { | ||
if (oUrl && !(options && options.noRevoke)) { | ||
loadImage.revokeObjectURL(oUrl) | ||
} | ||
if (callback) { | ||
callback(loadImage.scale(img, options)) | ||
} | ||
img.onerror = function (event) { | ||
return loadImage.onerror(img, event, file, callback, options) | ||
} | ||
img.onload = function (event) { | ||
return loadImage.onload(img, event, file, callback, options) | ||
} | ||
if (loadImage.isInstanceOf('Blob', file) || | ||
@@ -39,5 +35,3 @@ // Files are also Blob instances, but some browsers | ||
loadImage.isInstanceOf('File', file)) { | ||
url = oUrl = loadImage.createObjectURL(file) | ||
// Store the file type for resize processing: | ||
img._type = file.type | ||
url = img._objectURL = loadImage.createObjectURL(file) | ||
} else if (typeof file === 'string') { | ||
@@ -59,6 +53,4 @@ url = file | ||
img.src = target.result | ||
} else { | ||
if (callback) { | ||
callback(e) | ||
} | ||
} else if (callback) { | ||
callback(e) | ||
} | ||
@@ -73,2 +65,9 @@ }) | ||
function revokeHelper (img, options) { | ||
if (img._objectURL && !(options && options.noRevoke)) { | ||
loadImage.revokeObjectURL(img._objectURL) | ||
delete img._objectURL | ||
} | ||
} | ||
loadImage.isInstanceOf = function (type, obj) { | ||
@@ -79,2 +78,20 @@ // Cross-frame instanceof check | ||
loadImage.transform = function (img, options, callback, file, data) { | ||
callback(loadImage.scale(img, options, data), data) | ||
} | ||
loadImage.onerror = function (img, event, file, callback, options) { | ||
revokeHelper(img, options) | ||
if (callback) { | ||
callback.call(img, event) | ||
} | ||
} | ||
loadImage.onload = function (img, event, file, callback, options) { | ||
revokeHelper(img, options) | ||
if (callback) { | ||
loadImage.transform(img, options, callback, file, {}) | ||
} | ||
} | ||
// Transform image coordinates, allows to override e.g. | ||
@@ -118,4 +135,3 @@ // the canvas orientation based on the orientation option, | ||
// Canvas render method, allows to override the | ||
// rendering e.g. to work around issues on iOS: | ||
// Canvas render method, allows to implement a different rendering algorithm: | ||
loadImage.renderImageToCanvas = function ( | ||
@@ -147,4 +163,3 @@ canvas, | ||
// This method is used to determine if the target image | ||
// should be a canvas element: | ||
// Determines if the target image should be a canvas element: | ||
loadImage.hasCanvasOption = function (options) { | ||
@@ -159,3 +174,3 @@ return options.canvas || options.crop || !!options.aspectRatio | ||
// object is passed as image, else the scaled image: | ||
loadImage.scale = function (img, options) { | ||
loadImage.scale = function (img, options, data) { | ||
options = options || {} | ||
@@ -201,3 +216,3 @@ var canvas = document.createElement('canvas') | ||
if (useCanvas) { | ||
options = loadImage.getTransformedOptions(img, options) | ||
options = loadImage.getTransformedOptions(img, options, data) | ||
sourceX = options.left || 0 | ||
@@ -204,0 +219,0 @@ sourceY = options.top || 0 |
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
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
610366
19747
4
22