From fbd4fc44e09b5c3e7e3d24903adeaf71faeef75f Mon Sep 17 00:00:00 2001 From: "james.cryer" Date: Tue, 27 Sep 2016 16:43:22 +0100 Subject: [PATCH] useCrossOrigin option and README changes --- README.md | 8 ++++++-- resemble.js | 13 ++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4e71e56..3616acc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Resemble.js ========== -Analyse and compare images with Javascript and HTML5. [Resemble.js Demo](http://huddle.github.com/Resemble.js/) +Analyse and compare images with Javascript and HTML5. [Resemble.js More info & Demo](http://huddle.github.com/Resemble.js/). If you need NodeJS support, take a look at [node-resemble](https://github.com/ddo/node-resemble) ![Two image diff examples side-by-side, one pink, one yellow.](https://raw.github.com/Huddle/Resemble.js/master/demoassets/readmeimage.jpg "Visual image comparison") @@ -71,7 +71,8 @@ resemble.outputSettings({ }, errorType: 'movement', transparency: 0.3, - largeImageThreshold: 1200 + largeImageThreshold: 1200, + useCrossOrigin: false }); // resembleControl.repaint(); ``` @@ -80,6 +81,9 @@ By default, the comparison algorithm skips pixels when the image width or height You can switch this modify this behaviour by setting the `largeImageThreshold` option to a different value. Set it to **0** to switch it off completely. +`useCrossOrigin` is true by default, you might need to set to false if you're using [Data URIs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs). + + -------------------------------------- Created by [James Cryer](http://github.com/jamescryer) and the Huddle development team. diff --git a/resemble.js b/resemble.js index 847e78b..67f6eda 100644 --- a/resemble.js +++ b/resemble.js @@ -64,12 +64,9 @@ URL: https://github.com/Huddle/Resemble.js }; var errorPixelTransformer = errorPixelTransform.flat; - var largeImageThreshold = 1200; - - var httpRegex = /^https?:\/\//; + var useCrossOrigin = true; var document = typeof window != "undefined" ? window.document : {}; - var documentDomainRegex = new RegExp('^https?://' + document.domain); var resemble = function( fileData ){ @@ -161,7 +158,9 @@ URL: https://github.com/Huddle/Resemble.js var fileReader; var hiddenImage = new Image(); - hiddenImage.setAttribute('crossorigin', 'anonymous'); + if(useCrossOrigin) { + hiddenImage.setAttribute('crossorigin', 'anonymous'); + } hiddenImage.onerror = function () { hiddenImage.onerror = null; //fixes pollution between calls @@ -723,6 +722,10 @@ URL: https://github.com/Huddle/Resemble.js largeImageThreshold = options.largeImageThreshold; } + if (options.useCrossOrigin !== undefined) { + useCrossOrigin = options.useCrossOrigin; + } + return this; };