hjyssg / ShiguReader

硬核宅宅资源管理器. Ultimate Manga Resource Manager
MIT License
400 stars 45 forks source link

imageMagickHelp.js improve #105

Closed hjyssg closed 3 years ago

hjyssg commented 3 years ago

function isConertable() =>单独做成一个 post 在client先问可不可以转换,然后再转换。两个 请求。

module.exports.minifyOneFile

不在通过 oldAvgImgSize判断

async function convertImage(imgFilePath, outputImgPath, oldAvgImgSize){
    try{
        let opt;

         const stat = await pfs.stat(p);
         const oldImgSize =    stat.size;
        if(oldImgSize > img_reduce_resolution_threshold){

            opt = [imgFilePath, "-strip", "-quality", img_convert_quality, "-resize", `${img_reduce_resolution_dimension}\>`, outputImgPath ];
        }else{
            opt = [imgFilePath, "-strip", "-quality", img_convert_quality, outputImgPath ];
        }

        let {stdout, stderr} = await execa("magick", opt);
        return {stdout, stderr};
    }catch(e){
        logFail("[convertImage]", e);
    }
}