vendor/assets/javascripts/locomotive/resizeImage.js in locomotivecms-3.3.0.rc2 vs vendor/assets/javascripts/locomotive/resizeImage.js in locomotivecms-3.3.0.rc3
- old
+ new
@@ -137,43 +137,56 @@
self.ctx.putImageData(self.src, 0, 0)
resolveLanczos(self);
}
function resolveLanczos (self) {
- var result = new Image()
+ var result = new Image();
result.onload = function () {
self.resultD.resolve(result)
}
result.onerror = function (err) {
self.resultD.reject(err)
}
+ result.crossOrigin = 'Anonymous';
result.src = self.canvas.toDataURL(self.type, self.quality)
}
// resize by stepping down
- window.resizeImageStep = function (img, width, height, quality) {
+ window.resizeImageStep = function(img, width, height, quality) {
+ var resultD = $.Deferred();
+ var _img = document.createElement('img');
+
+ _img.onload = function() {
+ window._resizeImageStep(_img, width, height, quality, resultD);
+ }
+
+ // prevent the browser to raise a security exception about
+ // a tainted canvas.
+ _img.setAttribute('crossOrigin','anonymous');
+ _img.src = img.getAttribute('src');
+
+ return resultD.promise();
+ }
+
+ window._resizeImageStep = function (img, width, height, quality, resultD) {
quality = quality || 1.0
- // var resultD = $q.defer()
- var resultD = $.Deferred()
var canvas = document.createElement( 'canvas' )
var context = getContext(canvas)
var type = "image/png"
var cW = img.naturalWidth
var cH = img.naturalHeight
var dst = new Image()
+ dst.crossOrigin = 'Anonymous';
var tmp = null
- //resultD.resolve(img)
- //return resultD.promise
-
- function stepDown () {
+ function stepDown() {
cW = Math.max(cW / 2, width) | 0
cH = Math.max(cH / 2, height) | 0
canvas.width = cW
canvas.height = cH
@@ -186,10 +199,11 @@
resultD.resolve(dst)
}
if (!tmp) {
tmp = new Image()
+ tmp.crossOrigin = 'Anonymous';
tmp.onload = stepDown
}
tmp.src = dst.src
}
@@ -202,11 +216,9 @@
resultD.resolve(dst)
} else {
stepDown()
}
-
- return resultD.promise()
}
function getContext (canvas) {
var context = canvas.getContext('2d')