收藏
回答

wx.compressImage重复压缩图片?

wx.compressImage重复压缩图片至指定大小,压一次后就没办法继续压

compressImage(src, limit) {
        return new Promise((resolve, reject) => {
            wx.compressImage({
                src: src,
                quality:70,
                success(res) => {
                    console.log('compress', res)
                    wx.getFileSystemManager().getFileInfo({
                        filePath: res.tempFilePath,
                        success(img) => {
                            if(img.size<limit*1024){
                                console.log('img1',img)
                                return resolve({done:truevalue:res})
                            }else{
                                console.log('img2',img)
                                return resolve({done:falsevalue:res})
                            }
                        },
                        fail(img) => {
                            console.log('img', img)
                            reject(img)
                        }
                    })


                },
                fail(res) => {
                    console.log('error')
                    reject(res)
                }
            })
        }).then((res) => {
            if (res.done) {
                console.log('img1', res)
                return  Promise.resolve(res)
            } else {
                console.log('img2', res)
                    return this.compressImage(res.value.tempFilePath, limit)
                
            }
        }).catch((err) => {
            return Promise.reject(err)
        })


    },
回答关注问题邀请回答
收藏

3 个回答

  • Demons
    Demons
    2022-07-11

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2022-07-11
    有用
    回复
  • .
    .
    2022-12-02

    怪不得呢,我以为只有我一个的这么报错,只能压缩一次,其他的就不行了。

    真机测试也一样!

    微信小程序这开发环境、文档我也是服了,步步坑,到处限制。。。无语了

    publicFunc.js? [sm]:97 imgSizeRet>>>>>>>>>>>>>>>>>true,245023
    publicFunc.js? [sm]:89 imgCompressRet>>>>>>>>>>>>>>>>>true,http://tmp/ShRIxqDlqRkK100d9492e338f8f4f48aee7db07c71f7.jpg
    publicFunc.js? [sm]:97 imgSizeRet>>>>>>>>>>>>>>>>>true,114226
    publicFunc.js? [sm]:120 imgCompressRet>>>>>>>>>>>>>>>>>true,http://tmp/Ki9aHxamFuB235134048aa66f9fc2a1948fed631b57f.jpg
    publicFunc.js? [sm]:127 imgSizeRet>>>>>>>>>>>>>>>>>true,114780
    publicFunc.js? [sm]:150 imgCompressRet>>>>>>>>>>>>>>>>>true,http://tmp/DATPuAs5q2D1dd48fea2dcfa0973c0a4f4f133aa676b.jpg
    publicFunc.js? [sm]:157 imgSizeRet>>>>>>>>>>>>>>>>>true,114861
    
    2022-12-02
    有用
    回复
  • 最爱中二の病
    最爱中二の病
    2022-07-11

    https://developers.weixin.qq.com/s/KvG7bFmu71AL

    代码片段,必需真机调试,开发工具无法运行

    2022-07-11
    有用
    回复
登录 后发表内容