diff --git a/thumbnail/Thumbnailer.go b/thumbnail/Thumbnailer.go index 94d6625..6ea2e98 100644 --- a/thumbnail/Thumbnailer.go +++ b/thumbnail/Thumbnailer.go @@ -92,18 +92,18 @@ func FiletypeSupported(ext string) bool { } func (this *Thumbnailer) RenderFile_NoCache(absPath string) ([]byte, error) { + return this.RenderFile_NoCache_MimeType(absPath, mime.TypeByExtension(filepath.Ext(absPath))) +} + +func (this *Thumbnailer) RenderFile_NoCache_MimeType(absPath, mimeType string) ([]byte, error) { fh, err := os.OpenFile(absPath, os.O_RDONLY, 0400) if err != nil { return nil, err } - defer fh.Close() - extension := strings.ToLower(filepath.Ext(absPath)) - - switch extension { - case ".jpg", ".jpeg": + if mimeType == `image/jpeg` { src, err := jpeg.Decode(fh) if err != nil { return nil, err @@ -111,7 +111,7 @@ func (this *Thumbnailer) RenderFile_NoCache(absPath string) ([]byte, error) { return this.RenderScaledImage(src) - case ".png": + } else if mimeType == `image/png` { src, err := png.Decode(fh) if err != nil { return nil, err @@ -119,7 +119,7 @@ func (this *Thumbnailer) RenderFile_NoCache(absPath string) ([]byte, error) { return this.RenderScaledImage(src) - case ".gif": + } else if mimeType == `image/gif` { src, err := gif.Decode(fh) if err != nil { return nil, err @@ -127,10 +127,10 @@ func (this *Thumbnailer) RenderFile_NoCache(absPath string) ([]byte, error) { return this.RenderScaledImage(src) - case ".avi", ".mkv", ".mp4", ".ogm", ".wmv", ".flv", ".rm", ".rmvb": + } else if strings.HasPrefix(mimeType, `video/`) { return this.RenderScaledFfmpeg(absPath) - default: + } else { return nil, ErrUnsupportedFiletype }