Gourmet Project
Resize images from Cloud Storage
Sample code:
package main
import (
"net/http"
"strconv"
"strings"
"github.com/sfeir-open-source/projects/goroot/src/gourmet/appengine/image"
)
func resizeHandler(w http.ResponseWriter, r *http.Request) {
split := strings.Split(r.URL.Path[1:], "/")
if len(split) < 2 {
return
}
bucketName := split[0]
objectName := split[1]
width, err := strconv.Atoi(split[2])
if err != nil {
w.WriteHeader(http.StatusInternalServerError);
return
}
contents, err := image.ResizeStorageImage(bucketName, objectName, width)
if err != nil {
w.WriteHeader(http.StatusInternalServerError);
return
}
w.Write(contents)
}
func main() {
http.HandleFunc("/", resizeHandler)
http.ListenAndServe(":8080", nil)
}
To preview the image, open up your browser at: http://127.0.0.1:8080//<image-name.png>/250