gm icon indicating copy to clipboard operation
gm copied to clipboard

PNG does not compress very well.

Open SupertigerDev opened this issue 5 years ago • 0 comments

So I'm using GM in my chat app to compress user uploaded images and it seems like it only works well for JPG format and not for PNG as its increasing the file size. Here is an example:

const gm = require("gm").subClass({ imageMagick: true })
const path = require("path")

// 1,235KB
const input = path.join(__dirname, "og.png")

const outputJPG = path.join(__dirname, "compressed.jpg")
const outputPNG = path.join(__dirname, "compressed.png")

// 39KB
gm(input)
    .resize(1920, 1080, ">")
    .quality(20)
    .autoOrient()
    .interlace("Plane")
    .write(outputJPG, err => {
        console.log(err)
    })

// 1,736 KB
gm(input)
    .resize(1920, 1080, ">")
    .quality(20)
    .autoOrient()
    .interlace("Plane")
    .write(outputPNG, err => {
        console.log(err)
    })

Any ideas to fix this?

SupertigerDev avatar Apr 28 '20 18:04 SupertigerDev