// output static file as base64 string // image must exist as file in /static func imagefileAsBase64(w http.ResponseWriter, r *http.Request, m map[string]interface{}) { c := appengine.NewContext(r) p := r.FormValue("p") if p == "" { p = "static/chartbg_400x960__480x1040__12x10.png" } f, err := os.Open(p) util_err.Err_http(w, r, err, false) defer f.Close() img, whichFormat, err := image.Decode(f) util_err.Err_http(w, r, err, false) c.Infof("format %v - subtype %T\n", whichFormat, img) imgRGBA, ok := img.(*image.RGBA) util_err.Err_http(w, r, ok, true, "source image was not convertible to image.RGBA - gifs or jpeg?") // => header with mime prefix always prepended // and its always image/PNG str_b64 := conv.Rgba_img_to_base64_str(imgRGBA) w.Header().Set("Content-Type", "text/html") io.WriteString(w, "<p>Image embedded in HTML as Base64:</p><img width=200px src=\"") io.WriteString(w, str_b64) io.WriteString(w, "\"> ") }
func SaveImageToDatastore(w http.ResponseWriter, r *http.Request, i *image.RGBA, key string) string { s := conv.Rgba_img_to_base64_str(i) internalType := fmt.Sprintf("%T", i) //buffBytes, _ := StringToVByte(s) // instead of []byte(s) key_combi, err := dsu.BufPut(w, r, dsu.WrapBlob{Name: key, VByte: []byte(s), S: internalType}, key) util_err.Err_http(w, r, err, false) return key_combi }