gpt4 book ai didi

javascript - 如何使用 DropzoneJS 压缩图像?

转载 作者:行者123 更新时间:2023-12-01 01:49:18 26 4
gpt4 key购买 nike

我目前正在尝试使用 DropzoneJS 压缩图像。我想按质量压缩图像,删除元数据等,而不仅仅是调整大小。我该怎么做?

最佳答案

我已经找到解决办法了。您将需要图像压缩库,可以在这里下载:https://xkeshi.github.io/image-compressor/

// "myDropzone" is the camelized version of the HTML element's ID
Dropzone.options.myDropzone = {
transformFile: function(file, done) {
const imageCompressor = new ImageCompressor();

imageCompressor.compress(file, {
// I assume the output image won't have the meta data anymore
checkOrientation: true,
// Limit output image width & height
// For controllable file size & avoid blank output image
// https://github.com/xkeshi/image-compressor#maxwidth
maxWidth: 8192,
maxHeight: 8192,
// 0.8 is the default and already good enough
// https://github.com/xkeshi/image-compressor#quality
quality: 0.6,
// Convert ALL PNG images to JPEG
convertSize: 0,
})
.then((result) => {
// Handle the compressed image file.
done(result)
})
.catch((err) => {
// Handle the error
throw err
})
}
};

关于javascript - 如何使用 DropzoneJS 压缩图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51688638/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com