如何选择图片进行裁剪后上传到云存储空间,重点是裁剪功能怎么实现?
发布于 6 年前 作者 lwei 4670 次浏览 来自 问答

本地选择上传的功能已经实现,图片大小如何控制正方形等裁剪,就像微信头像显示的比例布局

btsImage(){

    let that = this

    console.log("上传imgage")

    wx.chooseImage({

      count:1,

      sizeType:['compressed'],

      sourceType:['album','camera'],


      success:(res)=>{

        wx.showLoading({

          title: '加载中',

        }),

        console.log(res)

        var timestamp = (new Date()).valueOf();

        console.log("图片时间")

        console.log(timestamp)

        console.log('res.tempFilePaths[0]',res.tempFilePaths[0])

        wx.cloud.uploadFile({         

          cloudPath:'users/image/'+app.globalData.username+'/'+timestamp,

          filePath: res.tempFilePaths[0],

          success:(res)=>{

            console.log(res)

            wx.hideLoading()

            that.setData({

              userimageUrl:res.fileID

            })

            wx.hideLoading({

              complete: (res) => {},

            })

            wx.showToast({

            title: '图片上传成功!',

            duration:2000

            })

          },

1 回复

搜索一下好多这种开源的项目,一般是用canvas实现。

回到顶部