Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1b106c

Browse files
committed
Added crossOrigin option for CORS enabled images. Fixes blueimp#19.
1 parent 9cce72f commit d1b106c

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
.PHONY: js
22

33
js:
4-
uglifyjs load-image.js -c -o load-image.min.js
4+
node_modules/.bin/uglifyjs load-image.js -c -m -o load-image.min.js

load-image.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Load Image 1.3.2
2+
* JavaScript Load Image 1.4
33
* https://github.com/blueimp/JavaScript-Load-Image
44
*
55
* Copyright 2011, Sebastian Tschan
@@ -30,17 +30,24 @@
3030
if (oUrl && !(options && options.noRevoke)) {
3131
loadImage.revokeObjectURL(oUrl);
3232
}
33-
callback(loadImage.scale(img, options));
33+
if (callback) {
34+
callback(loadImage.scale(img, options));
35+
}
3436
};
35-
if ((window.Blob && file instanceof Blob) ||
36-
// Files are also Blob instances, but some browsers
37-
// (Firefox 3.6) support the File API but not Blobs:
38-
(window.File && file instanceof File)) {
37+
if (loadImage.isInstanceOf('Blob', file) ||
38+
// Files are also Blob instances, but some browsers
39+
// (Firefox 3.6) support the File API but not Blobs:
40+
loadImage.isInstanceOf('File', file)) {
3941
url = oUrl = loadImage.createObjectURL(file);
4042
// Store the file type for resize processing:
4143
img._type = file.type;
4244
} else if (typeof file === 'string') {
4345
url = file;
46+
if (options && options.crossOrigin) {
47+
img.crossOrigin = options.crossOrigin;
48+
}
49+
} else {
50+
return img;
4451
}
4552
if (url) {
4653
img.src = url;
@@ -51,7 +58,9 @@
5158
if (target && target.result) {
5259
img.src = target.result;
5360
} else {
54-
callback(e);
61+
if (callback) {
62+
callback(e);
63+
}
5564
}
5665
});
5766
},
@@ -61,6 +70,11 @@
6170
(window.URL && URL.revokeObjectURL && URL) ||
6271
(window.webkitURL && webkitURL);
6372

73+
loadImage.isInstanceOf = function (type, obj) {
74+
// Cross-frame instanceof check
75+
return Object.prototype.toString.call(obj) === '[object ' + type + ']';
76+
};
77+
6478
// Detects subsampling in JPEG images:
6579
loadImage.detectSubsampling = function (img) {
6680
var iw = img.width,

load-image.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blueimp-load-image",
3-
"version": "1.3.2",
3+
"version": "1.4.0",
44
"title": "JavaScript Load Image",
55
"description": "JavaScript Load Image is a function to load images provided as File or Blob objects or via URL. It returns an optionally scaled HTML img or canvas element.",
66
"keywords": [
@@ -31,6 +31,9 @@
3131
"type": "git",
3232
"url": "git://github.com/blueimp/JavaScript-Load-Image.git"
3333
},
34+
"devDependencies": {
35+
"uglify-js": "2.2.5"
36+
},
3437
"bugs": "https://github.com/blueimp/JavaScript-Load-Image/issues",
3538
"licenses": [
3639
{

0 commit comments

Comments
 (0)