用到了nativeImage
引用import { nativeImage} from 'electron'
const imagebuff = nativeImage.createFromPath(path)
//等比缩放到特定大小
let sizeContent = imagebuff.getSize()
let calibration = sizeContent.width > sizeContent.height ? 'width' : 'height'
const res = imagebuff.resize({
quality: 'good', //压缩等级
[calibration]: 100 //特定大小100px
})
// const imageData = res.toPNG()
// jpg 压缩 图片质量设置
const imageData = res.toJPEG(quality) //输出缩略图的buffer
return imageData
参考 https://vue-js.com/topic/6022286496b2cb0032c389c6