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.73k stars 341 forks source link

result image content length has changed significantly since v1.0.11 for large source/input images #218

Open scott-seo opened 6 years ago

scott-seo commented 6 years ago

golang version: 1.9.2 vips version: 8.6.1 OS: OSX 10.12.6 Sierra

how to replicate the issue

check out v1.0.10 and download this large image over to fixtures folder

git checkout 32e459e

curl -O https://static.pexels.com/photos/431732/pexels-photo-431732.jpeg 

mv pexels-photo-431732.jpeg fixtures/test_large.jpg

then run the following test

func TestImageResizeLarge(t *testing.T) {
    buf, err := initImage("test_large.jpg").Resize(300, 240)
    if err != nil {
        t.Errorf("Cannot process the image: %#v", err)
    }

    err = assertSize(buf, 300, 240)
    if err != nil {
        t.Error(err)
    }

    // v1.0.10 buf length is 13103
    // >= v1.0.11 buf length is 35814
    // if len(buf) > 13103 {
    //  t.Errorf("resize buf length is bigger than expected length 13103")
    //}

    Write("fixtures/test_resize_large_out.jpg", buf)
}

Verify that result image, fixtures/test_resize_large_out.jpg file length is 13103

Check out v1.0.11 and rerun the same test

git checkout d7007ce

curl -O https://static.pexels.com/photos/431732/pexels-photo-431732.jpeg 

mv pexels-photo-431732.jpeg fixtures/test_large.jpg

Rerun the same test from above and see that result image which is fixtures/test_resize_large_out.jpg file length is now 35814.

The source image, test_large.jpg is roughly 14 meg. This may not be happening for smaller images. I will compare the changes between v1.0.10 and v1.0.11.

v1.0.17 has the same issue.

Any help or insight into why this would be greatly appreciated.

scott-seo commented 6 years ago

I am going to answer my own issue.

So it turns out StripMetadata was added to Options after v1.0.10 The default boolean value for this field is false.

By trial and error I ended up setting StripMetadata to true. That gave me result image file length that is close to what it used to be. I am seeing 13019 bytes as file length. 6 bytes more than before. I can live with that.

I just wish this field default value is set to true. This would have came across as regression test failure in my organization.

Can this be documented or can the default value be changed to true so others can be saved from the trouble I went through?