diff --git a/src/util.js b/src/util.js index d927816..8d3ffac 100644 --- a/src/util.js +++ b/src/util.js @@ -229,7 +229,7 @@ const loadImageAsync = (item, resolve, reject) => { image.crossOrigin = item.cors } - image.onload = function () { + function onLoad () { resolve({ naturalHeight: image.naturalHeight, naturalWidth: image.naturalWidth, @@ -237,9 +237,16 @@ const loadImageAsync = (item, resolve, reject) => { }) } - image.onerror = function (e) { + function onError (e) { reject(e) } + + if (typeof image.decode === 'function') { + image.decode().then(onLoad, onError) + } else { + image.onload = onLoad + image.onerror = onError + } } const style = (el, prop) => {