1 2 3 4 5 6 7 8 9 10
| var img = new Image(); img.onload = function(data){ var obj ={ uri:src, width:data.path["0"].width, height:data.path["0"].height }); } img.src = src;
|
在android设备中可以得到图片的宽高 在iso设备中img.onload 返回结果是 isTrusted:true 由于使用的是阿里云oss服务 http://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/info
1 2 3 4 5 6 7
| { "FileSize": {"value": "21839"}, "Format": {"value": "jpg"}, "ImageHeight": {"value": "267"}, "ImageWidth": {"value": "400"} }
|
最终结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| getImgInfo:function(srcArr,newSrcArr){ var arr = []; var len = srcArr.length; var num = 0; return new Promise(function(resolve,reject){ srcArr.forEach(function(src,index,array){ if($.device.ios){ axios.get(newSrcArr[index]+"?x-oss-process=image/info").then(function(r){ vPage.homework.body = JSON.stringify(r.data.ImageHeight.value); arr.push({ uri:newSrcArr[index], width:r.data.ImageWidth.value, height:r.data.ImageHeight.value }); num += 1; if(num == len){ resolve(arr) } }) }else{ var img = new Image(); img.onload = function(data){ arr.push({ uri:newSrcArr[index], width:data.path["0"].width, height:data.path["0"].height }); num += 1; if(num == len){ resolve(arr) } } img.src = src; } }) }) }
|