Example #1
0
// GET /showimg?name=${name}&size=${size}&rect=${rect}
func handleShowImg(w http.ResponseWriter, r *http.Request) {
	var size image.Point
	var rect image.Rectangle

	fmt.Printf("handleShowImg: %q\n", r.URL)
	vals := r.URL.Query()
	name := vals.Get("name")
	img := readImageAsRgba(name)
	if img == nil {
		http.Error(w, fmt.Sprintf("couldn't load image %q", name), http.StatusInternalServerError)
		return
	}

	sizeStr := vals.Get("size")
	size, _ = ParseSize(sizeStr)
	rectStr := vals.Get("rect")
	rect, _ = ParseRectangle(rectStr)

	model := struct {
		Name       string
		OrigBounds image.Rectangle
		SizeArg    string
		SizeHuman  string
		RectArg    string
		RectHuman  string
	}{
		Name:       name,
		OrigBounds: img.Bounds(),
		SizeArg:    sizeStr,
		SizeHuman:  size.String(),
		RectArg:    rectStr,
	}
	if rectStr != "" {
		model.RectHuman = rect.String()
	}
	execTemplate(w, tmplShowImg, model)
}