imageminJpegTran 附加组件旋转图像

imageminJpegTran add-on rotates an image

我正在做的是压缩我从文件中获得的缓冲区,然后再次将压缩后的缓冲区写入内存。发生的情况是正方形和矩形图像被正确压缩,但垂直图像被旋转。是否有任何选项可以传递给 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)
    }
    
}

我最终使用了另一个名为 imagemin-mozjpeg 的插件。 它允许压缩图像而不旋转它。

const fs = require("fs");
const imagemin = require("imagemin");
const imageMozg = require("imagemin-mozjpeg");
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: [
                imageMozg({
                        quality: 75, 
                        progressive: true
                    }),
                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)
    }
    
}