//上传头像图片
function uploadHead(imgPath) {
console.log("imgPath = " + imgPath);
var image = new Image();
image.onload = function() {
var imgData = getBase64Image(image);
/*在这里调用上传接口*/
mui.ajax($serverPath + "app/modifyHead", {
data: {
'imgData': imgData,
'userId': plus.storage.getItem("userId")
},
dataType: 'json',
type: 'post',
timeout: 10000,
success: function(data) {
if(data.result == 'yes') {
$newHead = data.newHeadPath;
console.log('上传成功!!!!!!!!!!' + $newHead);
plus.storage.setItem("userHead", $newHead);
mui.toast("头像修改成功!");
} else {
mui.toast("头像上传失败!");
}
},
error: function(xhr, type, errorThrown) {
mui.toast('网络异常,请稍后再试!');
}
});
}
image.src = imgPath;
image.style.width = "60px";
image.style.height = "60px";
console.log("haha");
}
//将图片压缩转成base64
function getBase64Image(img) {
var canvas = document.createElement("canvas");
var width = img.width;
var height = img.height;
// calculate the width and height, constraining the proportions
if(width > height) {
if(width > 100) {
height = Math.round(height *= 100 / width);
width = 100;
}
} else {
if(height > 100) {
width = Math.round(width *= 100 / height);
height = 100;
}
}
canvas.width = width; /*设置新的图片的宽度*/
canvas.height = height; /*设置新的图片的长度*/
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height); /*绘图*/
var dataURL = canvas.toDataURL("image/png", 0.8);
return dataURL.replace("data:image/png;base64,", "");
}

最新文章

  1. AndroidProjects个人项目归纳
  2. mysql存储过程编写-入门案例-遁地龙卷风
  3. LeetCode之389. Find the Difference
  4. golang实现随机数
  5. HBase与MongDB等NoSQL数据库对照
  6. 0525Scram项目6.0
  7. Eclipse中FindBugs插件的应用
  8. Myeclipse6.0 在线安装svn插件
  9. 线程操作案例--生产者与消费者,Object类对线程的支持
  10. Pascal’s Triangle
  11. 了解ThinkPHP(一)
  12. struts2学习笔记(4)——数据类型转换
  13. hive 桶相关特性分析
  14. python 程序穩定性閒談-續集
  15. Oracle EBS-SQL (WIP-10):检查车间任务状态“完成”但未发料数据.sql
  16. String.getBytes()--->字符串转字节数组
  17. asp 操作 json
  18. 设计理念 : popup login 在前后台
  19. java 三种工厂模式
  20. hbase的一些要点

热门文章

  1. linux解压eclipse启动时无法找到jre环境的解决办法
  2. VGG使用重复元素的网络
  3. shiro密码的比对,密码的MD5加密,MD5盐值加密,多个Relme
  4. Vue中引入jquery方法 vue-cli webpack 引入jquery
  5. 搭建一个redis高可用系统
  6. Entity Framework中DbContext结合TransactionScope提交事务的正确方式
  7. 微信小程序获取手机信息
  8. 大数据框架-Hbase
  9. 解决Windows10下小娜无法搜索本地应用的问题
  10. 12种开源Web安全扫描程序