我正在做的是压缩从文件中获得的缓冲区并将压缩后的缓冲区再次写入内存。发生的情况是方形和矩形图像被正确压缩,但垂直图像被旋转。我可以将任何选项传递给 imageminJpegtran 插件,以便图像保持不变,只是压缩?这是我的代码:
const fs = require("fs");
const imagemin = require("imagemin");
const imageminJpegtran = require('imagemin-jpegtran');
const imageminPngquant = require('imagemin-pngquant');
async function outputFile() {
let imageBase64 = fs.readFileSync("test_ios.jpg", {encoding: "base64"})
const butmap = Buffer.from(imageBase64, "base64")
try {
let compressedBuffer = await imagemin.buffer(butmap, {
plugins: [
imageminJpegtran(),
imageminPngquant({
quality: [0.1, 0.8]
})
]
});
compressedBuffer = compressedBuffer.toString("base64");
const compressedBitmap = Buffer.from(compressedBuffer, "base64")
fs.writeFileSync("./test_ios_copy.jpg", compressedBitmap)
} catch (error) {
console.log(error)
}
}