From 9424bf5f1a2f329c03079bc95c743918503669c4 Mon Sep 17 00:00:00 2001 From: tcme <546900+thisconnect@users.noreply.github.com> Date: Fri, 5 Apr 2019 11:43:42 +0200 Subject: [PATCH 1/4] adds crossOrigin attribute to loadImage without that using the image later with webgl errors DOMException: Failed to execute 'texImage2D' on 'WebGLRenderingContext': The image element contains cross-origin data, and may not be loaded. --- browser.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/browser.js b/browser.js index c0a7b9fa8..3a217bf5b 100644 --- a/browser.js +++ b/browser.js @@ -21,7 +21,8 @@ exports.createImageData = function (array, width, height) { exports.loadImage = function (src) { return new Promise((resolve, reject) => { const image = document.createElement('img') - + image.crossOrigin = "anonymous" + function cleanup () { image.onload = null image.onerror = null From 3e30bd8b732a5eb071b099bda1bb15e665f00ce7 Mon Sep 17 00:00:00 2001 From: tcme <546900+thisconnect@users.noreply.github.com> Date: Sun, 7 Apr 2019 13:43:50 +0200 Subject: [PATCH 2/4] Standard Style --- browser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser.js b/browser.js index 3a217bf5b..9563f64f8 100644 --- a/browser.js +++ b/browser.js @@ -21,8 +21,8 @@ exports.createImageData = function (array, width, height) { exports.loadImage = function (src) { return new Promise((resolve, reject) => { const image = document.createElement('img') - image.crossOrigin = "anonymous" - + image.crossOrigin = 'anonymous' + function cleanup () { image.onload = null image.onerror = null From 4dc261f4451840ed075d2462230d6bffb6c8099d Mon Sep 17 00:00:00 2001 From: tcme <546900+thisconnect@users.noreply.github.com> Date: Sat, 20 Apr 2019 09:28:19 +0200 Subject: [PATCH 3/4] support any properties on an HTMLImageElement https://github.com/Automattic/node-canvas/pull/1402#issuecomment-484494249 --- browser.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/browser.js b/browser.js index 9563f64f8..3077111ca 100644 --- a/browser.js +++ b/browser.js @@ -18,10 +18,9 @@ exports.createImageData = function (array, width, height) { } } -exports.loadImage = function (src) { +exports.loadImage = function (src, options) { return new Promise((resolve, reject) => { - const image = document.createElement('img') - image.crossOrigin = 'anonymous' + const image = Object.assign(document.createElement('img'), options) function cleanup () { image.onload = null From 55b24fbe26a9612464cc8b683bc48d458b118c6e Mon Sep 17 00:00:00 2001 From: tcme <546900+thisconnect@users.noreply.github.com> Date: Sun, 21 Apr 2019 09:46:56 +0200 Subject: [PATCH 4/4] loadImage accepts any options now --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index e190da16e..8cc1708ee 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -294,7 +294,7 @@ export function createImageData(width: number, height: number): ImageData * @param src URL, `data: ` URI or (Node.js only) a local file path or Buffer * instance. */ -export function loadImage(src: string|Buffer): Promise +export function loadImage(src: string|Buffer, options?: any): Promise /** * Registers a font that is not installed as a system font. This must be used