30 lines
438 B
Go
30 lines
438 B
Go
package main
|
|
|
|
import (
|
|
"image"
|
|
"image/png"
|
|
"os"
|
|
)
|
|
|
|
func encodePNG(path string, im image.Image) error {
|
|
dst, err := os.Create(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer dst.Close()
|
|
return png.Encode(dst, im)
|
|
}
|
|
|
|
func decodeImage(path string) (image.Image, error) {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
im, _, err := image.Decode(f)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return im, nil
|
|
}
|