h2non / bimg

Go package for fast high-level image processing powered by libvips C library
https://pkg.go.dev/github.com/h2non/bimg?tab=doc
MIT License
2.63k stars 338 forks source link

png not compressing (quality) and it's size is increasing #392

Open xerenahmed opened 2 years ago

xerenahmed commented 2 years ago

code sample:

options := bimg.Options{
    Quality:  quality,
    Lossless: true,
}
newImage := imgBuf.Bytes()
newImage, err = bimg.NewImage(imgBuf.Bytes()).Process(options)

image is jpeg by default.

the image: 00042b7d-d3d4-466a-8e79-b49f22904b98_big

aksdb commented 2 years ago

What's the expectation here? PNG is a lossless format and optimized for computer graphics, not photos. JPEG achieves its smaller size due to its lossy compression. So I don't see how the PNG could be smaller than the JPEG, even at high (lossless!) compression.

IMO the only way out would be to use a lossy compression (imagequant does that for example), but that more or less destroys the advantage of PNG.