UNPKG

util-helpers

Version:

一个基于业务场景的工具方法库

27 lines (24 loc) 776 B
import { isBlob } from 'ut2'; import { createObjectURL, revokeObjectURL } from './utils/native.js'; function loadImage(img) { return new Promise(function (resolve, reject) { var imgIsBlob = isBlob(img); var url = imgIsBlob ? createObjectURL(img) : img; var image = new Image(); if (!imgIsBlob) { image.crossOrigin = 'anonymous'; } image.onload = function () { resolve(image); }; image.onerror = function (err) { if (imgIsBlob) { revokeObjectURL(url); } console.error("[loadImage] The image load failed, '".concat(img, "'.")); reject(err); }; image.src = url; }); } export { loadImage as default };