💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
//下载图片 var reg = new RegExp(/(.png|.jpg|.jpeg|.gif)/g, "i"); if ( data && data.file_name && data.file_name.match(reg) && data.file_name.match(reg).length > 0 ) { // 图片转base64地址 var fixtype = function() { var r = data.file_name.match(reg); return "image/" + r; }; var images = new Image(); var canvas = document.createElement("canvas"); var context = canvas.getContext("2d"); images.crossOrigin = "anonymous"; images.src = data.file_url; images.onload = function() { var _w = images.naturalWidth; var _h = images.naturalHeight; canvas.width = _w; canvas.height = _h; context.drawImage(images, 0, 0); var a = document.createElement("a"); a.href = canvas.toDataURL(fixtype()); //将画布内的信息导出为png图片数据 a.download = data.file_name; //设定下载名称 a.click(); //点击触发下载 };