Beispiel #1
0
func (d *gcsDriver) Open(id string) (driver.RFile, error) {
	f, err := file.Open(d.c, d.path(id))
	if err != nil {
		return nil, err
	}
	return rfile{f}, nil
}
Beispiel #2
0
func renderMeme(ctx appengine.Context, w io.Writer, id, topText, botText string) error {
	// Read template.
	templateName := templateFile(id)
	reader, err := file.Open(ctx, gcsFilesApiPath(bucket, templateName))
	if err != nil {
		return err
	}
	defer reader.Close()

	bgImg, err := jpeg.Decode(reader)
	if err != nil {
		return err
	}

	img := image.NewRGBA(bgImg.Bounds())
	draw.Draw(img, bgImg.Bounds(), bgImg, image.ZP, draw.Src)

	c := freetype.NewContext()
	c.SetDPI(72)
	c.SetFont(font)
	c.SetClip(img.Bounds())
	c.SetDst(img)
	c.SetHinting(freetype.FullHinting)

	drawFitCentered(c, topText, img, false)
	drawFitCentered(c, botText, img, true)

	err = jpeg.Encode(w, img, &jpeg.Options{Quality: 75})
	if err != nil {
		return err
	}

	return nil
}