示例#1
0
func loadSize(ctxt *fs.Context, name string, max int) *image.RGBA {
	data, _, err := ctxt.Read("qr/upload/" + name + ".png")
	if err != nil {
		panic(err)
	}
	i, _, err := image.Decode(bytes.NewBuffer(data))
	if err != nil {
		panic(err)
	}
	b := i.Bounds()
	dx, dy := max, max
	if b.Dx() > b.Dy() {
		dy = b.Dy() * dx / b.Dx()
	} else {
		dx = b.Dx() * dy / b.Dy()
	}
	var irgba *image.RGBA
	switch i := i.(type) {
	case *image.RGBA:
		irgba = resize.ResizeRGBA(i, i.Bounds(), dx, dy)
	case *image.NRGBA:
		irgba = resize.ResizeNRGBA(i, i.Bounds(), dx, dy)
	}
	return irgba
}
示例#2
0
func flag(w http.ResponseWriter, req *http.Request, img string, ctxt *fs.Context) {
	if !isImgName(img) && !isTagName(img) {
		fmt.Fprintf(w, "Invalid image.\n")
		return
	}
	data, _, _ := ctxt.Read("qr/flag/" + img)
	data = append(data, '!')
	ctxt.Write("qr/flag/"+img, data)

	fmt.Fprintf(w, "Thank you.  The image has been reported.\n")
}
示例#3
0
func runTemplate(c *fs.Context, w http.ResponseWriter, name string, data interface{}) {
	t := template.New("main")

	main, _, err := c.Read(name)
	if err != nil {
		panic(err)
	}
	style, _, _ := c.Read("style.html")
	main = append(main, style...)
	_, err = t.Parse(string(main))
	if err != nil {
		panic(err)
	}

	var buf bytes.Buffer
	if err := t.Execute(&buf, &data); err != nil {
		panic(err)
	}
	w.Write(buf.Bytes())
}