Skip to content

Bug fix for handling CDN image sources to be manipulated in JS canvas #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion blur.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@
var formattedSource = ($source.css('backgroundImage')).replace(/"/g, "").replace(/url\(|\)$/ig, "");
ctx = canvas.getContext('2d');
tempImg = new Image();

//Some image sources (eg. images form s3) doesnot allow to be manipulated in
//javascript canvas. The following attribute helps to overcome this security
//issue and the exceptions thrown from stackBlurCanvasRGB are less probable to
//happen if this attrib is set.
//NOTE: you still need to set the correct CORS config in CDNs
if(formattedSource.match(/http:\/\/|https:\/\//)) {
tempImg.setAttribute('crossorigin', 'anonymous');
}

tempImg.onload = function () {
if(!isCached) {
canvas.style.display = "none";
Expand Down Expand Up @@ -280,4 +290,4 @@
}
});
};
})(jQuery);
})(jQuery);