Skip to content

Commit

Permalink
Register image handler for image transformations fixes gohugoio#1014
Browse files Browse the repository at this point in the history
  • Loading branch information
kujohn committed Jan 6, 2016
1 parent 9a6dc6c commit 5457f14
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions hugolib/handler_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
package hugolib

import (
"image"
_ "image/jpeg"
_ "image/png"

"log"

"github.com/dchest/cssmin"
"github.com/spf13/hugo/helpers"
"github.com/spf13/hugo/source"
Expand All @@ -22,6 +28,7 @@ import (

func init() {
RegisterHandler(new(cssHandler))
RegisterHandler(new(imageHandler))
RegisterHandler(new(defaultHandler))
}

Expand Down Expand Up @@ -51,3 +58,13 @@ func (h cssHandler) FileConvert(f *source.File, s *Site) HandledResult {
s.WriteDestFile(f.Path(), helpers.BytesToReader(x))
return HandledResult{file: f}
}

type imageHandler struct{ basicFileHandler }

func (h imageHandler) Extensions() []string { return []string{"jpg", "jpeg", "png", "gif"} }
func (h imageHandler) FileConvert(f *source.File, s *Site) HandledResult {
_, ext, err := image.Decode(f.Contents)
log.Println(ext, err)
s.WriteDestFile(f.Path(), f.Contents)
return HandledResult{file: f}
}

0 comments on commit 5457f14

Please sign in to comment.