I am currently playing around with golang and Martini and such and wanted to dynamically serve some manipulated/generated images. Here's a minimal example:
package main
import (
"github.com/codegangsta/martini"
"github.com/nfnt/resize"
"image"
"image/jpeg"
"log"
"os"
)
func thumb() image.Image {
file, err := os.Open("test.jpg")
if err != nil {
log.Fatal(err)
}
img, err := jpeg.Decode(file)
if err != nil {
log.Fatal(err)
}
file.Close()
m := resize.Resize(0, 200, img, resize.MitchellNetravali)
return m
}
func main() {
m := martini.Classic()
m.Get("/") image.Image {
return thumb()
})
m.Run()
}
That compiles fine, but instead of serving an image, I get some "Content-Type:text/plain; charset=utf-8" that looks like this:
<*image.RGBA64 Value>
I am pretty sure that I need to encode the image again and then serve it. But im not quite sure how to do this without saving the image to the disk...
Thanks in advance!