better reusing media methods

pull/12/head
Stephen Searles 7 years ago
parent df18b29087
commit 6d479bb925
  1. 14
      media/media.go

@ -168,12 +168,7 @@ func (ms *MediaSource) ThumbMax(m Media, maxDim int) (string, image.Rectangle, e
return "", image.ZR, err
}
img, _, err := image.Decode(f)
if err != nil {
return "", image.ZR, err
}
src, err := ms.ThumbImage(img, m, size)
src, err := ms.thumbReader(f, m, size)
return src, size, err
}
@ -207,7 +202,11 @@ func (ms *MediaSource) Thumb(m Media, size image.Rectangle) (string, error) {
}
defer f.Close()
img, _, err := image.Decode(f)
return ms.thumbReader(f, m, size)
}
func (ms *MediaSource) thumbReader(r io.Reader, m Media, size image.Rectangle) (string, error) {
img, _, err := image.Decode(r)
if err != nil {
return "", err
}
@ -216,7 +215,6 @@ func (ms *MediaSource) Thumb(m Media, size image.Rectangle) (string, error) {
}
func (ms *MediaSource) ThumbImage(img image.Image, m Media, size image.Rectangle) (string, error) {
thumbLoc := ms.ThumbFilename(m, size)
os.MkdirAll(path.Dir(thumbLoc), 0755)
fthumb, err := os.OpenFile(thumbLoc, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0655)

Loading…
Cancel
Save