Javascript实现http路径转换成base64
// http -> base64
export const getHttpUrlBase64 = (httpurl) => {
return new Promise((resolve, reject) => {
const createImg = new Image()
createImg.crossOrigin = 'Anonymous'
createImg.src = httpurl + '?v=' + Math.random()
createImg.onload = () => {
const canvas = document.createElement('canvas')
const width = createImg.width
const height = createImg.height
canvas.width = width
canvas.height = height
canvas.getContext('2d').drawImage(createImg, 0, 0, width, height)
resolve(canvas.toDataURL('image/jpeg'))
}
})
}
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
感谢分享 赞一个
欢迎欢迎O(∩_∩)O