disintegration / imaging

Imaging is a simple image processing package for Go
MIT License
5.3k stars 443 forks source link

png: generate 0 bytes file after resizing and compression #129

Closed jnlin closed 4 years ago

jnlin commented 4 years ago

Go version

jnlinmacbookpro:src jnlin$ go version
go version go1.14.6 darwin/amd64

Reproducible Code Below:

package main

import (
    "bufio"
    "image/png"
    "os"

    "github.com/disintegration/imaging"
)

func main() {

    img, err := imaging.Open("reproduce.png")
    if err != nil {
        return
    }
    imaging.Resize(img, 600, 600, imaging.Lanczos)

    f1, err := os.Create("output_defaultcompression.png")
    if err != nil {
        return
    }
    w1 := bufio.NewWriter(f1)
    imaging.Encode(w1, img, imaging.PNG, imaging.PNGCompressionLevel(png.DefaultCompression))

    f2, err := os.Create("output_nocompression.png")
    if err != nil {
        return
    }
    w2 := bufio.NewWriter(f2)
    imaging.Encode(w2, img, imaging.PNG, imaging.PNGCompressionLevel(png.NoCompression))
}

The result:

jnlinmacbookpro:pixpic-go jnlin$ ls -al *.png
-rw-r--r--  1 jnlin  staff       0  9  2 11:19 output_defaultcompression.png
-rw-r--r--  1 jnlin  staff  641130  9  2 11:19 output_nocompression.png
-rw-r--r--  1 jnlin  staff    3102  9  2 11:04 reproduce.png

The original PNG file is attached as ZIP files to avoid processing by GitHub. image.zip

Expected Result:

Correct output PNG file

disintegration commented 4 years ago

See https://github.com/disintegration/imaging/issues/75

jnlin commented 4 years ago

It works, thanks!