Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check errors from Close method in SavePNG and SaveJPG #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ func SavePNG(path string, im image.Image) error {
if err != nil {
return err
}
defer file.Close()
return png.Encode(file, im)
if err := png.Encode(file, im); err != nil {
return err
}
return file.Close()
}

func LoadJPG(path string) (image.Image, error) {
Expand All @@ -68,12 +70,14 @@ func SaveJPG(path string, im image.Image, quality int) error {
if err != nil {
return err
}
defer file.Close()

var opt jpeg.Options
opt.Quality = quality

return jpeg.Encode(file, im, &opt)
if err := jpeg.Encode(file, im, &opt); err != nil {
return err
}
return file.Close()
}

func imageToRGBA(src image.Image) *image.RGBA {
Expand Down