Save thumbnails
This commit is contained in:
parent
99e09acb56
commit
859ee3e8be
1 changed files with 15 additions and 1 deletions
16
picture.go
16
picture.go
|
@ -13,6 +13,8 @@ import (
|
|||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/nfnt/resize"
|
||||
)
|
||||
|
||||
type Picture struct {
|
||||
|
@ -120,8 +122,20 @@ func AddImage(filename string, blob io.ReadCloser) (error) {
|
|||
return err
|
||||
} else {
|
||||
fw.Close()
|
||||
return nil
|
||||
|
||||
thumb := resize.Thumbnail(300, 185, img, resize.Lanczos3)
|
||||
|
||||
// Save thumbnail
|
||||
if fw, err := os.Create(filepath.Join(ThumbsDir, filename + ".jpg")); err != nil {
|
||||
return err
|
||||
} else if err := jpeg.Encode(fw, thumb, nil); err != nil {
|
||||
return err
|
||||
} else {
|
||||
fw.Close()
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p Picture) Publish() (error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue