From e6dab9aaf06415bd62cadb5d72a09bcc37b56128 Mon Sep 17 00:00:00 2001 From: Shadowblazen Date: Thu, 31 Jul 2014 20:58:33 -0700 Subject: [PATCH] Updated crossorigin settings The crossorigin settings are currently breaking image tests in Firefox and Safari when the images are not cross-domain (e.g. images specified as base64 strings, or using relative pathing). This change enables CORS on the image if and only if the image is 1) specified using absolute pathing with the HTTP or HTTPS protocol and 2) the image is from a different domain than resemble.js is being run on. --- resemble.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resemble.js b/resemble.js index c9045fb..e26bcc1 100644 --- a/resemble.js +++ b/resemble.js @@ -37,6 +37,9 @@ URL: https://github.com/Huddle/Resemble.js var errorPixelTransformer = errorPixelTransform.flat; var largeImageThreshold = 1200; + + var httpRegex = /^https?:\/\//; + var documentDomainRegex = new RegExp('^https?://' + document.domain); _this['resemble'] = function( fileData ){ @@ -110,7 +113,10 @@ URL: https://github.com/Huddle/Resemble.js function loadImageData( fileData, callback ){ var fileReader; var hiddenImage = new Image(); - hiddenImage.setAttribute("crossOrigin", "crossOrigin"); + + if (httpRegex.test(fileData) && !documentDomainRegex.test(fileData)) { + hiddenImage.setAttribute('crossorigin', 'anonymous'); + } hiddenImage.onload = function() {