读取到当前的文件数据以后,我们还需要使用js的Buffer类进行数据转换: 先用buffer将数据进行缓存 const buffer = new Buffer(data, 'binary'); 1. 然后获取到图片的base64格式数据: buffer.toString('base64') 1. 由于获取到的base64不含有前面的图片类型等内容,所以,我们赋值给image对象的时候,还需要添加上相应...
function convertImgToBase64(url, callback, outputFormat){ var canvas = document.createElement('CANVAS'), ctx = canvas.getContext('2d'), img = new Image; img.crossOrigin = 'Anonymous'; img.onload = function(){ canvas.height = img.height; canvas.width = im...
nodejs读取服务器图片,转为base64显示在网页上 constfs =require("fs");constmineType =require("mime-types");functionimgToBase64(url) {try{letimgurl = config.imageUrl;letimageData = fs.readFileSync(imgurl);if(!imageData)return"";letbufferData =Buffer.from(imageData).toString("base64");let...