1 Star 0 Fork 0

zhangle/t-node-canvas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
browser.js 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
Matt Huggins 提交于 2019-03-22 10:57 . Fix ES6 syntax for IE
/* globals document, ImageData */
const parseFont = require('./lib/parse-font')
exports.parseFont = parseFont
exports.createCanvas = function (width, height) {
return Object.assign(document.createElement('canvas'), { width: width, height: height })
}
exports.createImageData = function (array, width, height) {
// Browser implementation of ImageData looks at the number of arguments passed
switch (arguments.length) {
case 0: return new ImageData()
case 1: return new ImageData(array)
case 2: return new ImageData(array, width)
default: return new ImageData(array, width, height)
}
}
exports.loadImage = function (src, options) {
return new Promise(function (resolve, reject) {
const image = Object.assign(document.createElement('img'), options)
function cleanup () {
image.onload = null
image.onerror = null
}
image.onload = function () { cleanup(); resolve(image) }
image.onerror = function () { cleanup(); reject(new Error('Failed to load the image "' + src + '"')) }
image.src = src
})
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zltube/t-node-canvas.git
git@gitee.com:zltube/t-node-canvas.git
zltube
t-node-canvas
t-node-canvas
master

搜索帮助