Example #1
0
func main() {
	var loop = flag.Bool("loop", false, "Loop the show")
	var resize = flag.Bool("resize", false, `Resize image to fit the screen.`)
	var bgcolor = flag.String("bg", "black", `Background color (named color or rgb(r,g,b)).`)
	var delay = flag.Duration("delay", 2*time.Second, "Delay between pictures")
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [ flags ] images...\n", os.Args[0])
		flag.PrintDefaults()
		os.Exit(1)
	}

	flag.Parse()
	w, h := openvg.Init()
	images := []image.Image{}
	imgcount := 0
	for _, imgfile := range flag.Args() {
		fmt.Fprintf(os.Stderr, "loading %q ", imgfile)
		img, err := getimage(imgfile, w, h, *resize)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			continue
		}
		images = append(images, img)
		imgcount++
		fmt.Fprintln(os.Stderr, "ok")
	}
	for {
		for _, img := range images {
			ib := img.Bounds()
			imw, imh := ib.Max.X-ib.Min.X, ib.Max.Y-ib.Min.Y
			openvg.Start(w, h)
			openvg.BackgroundColor(*bgcolor)
			x, y := openvg.VGfloat(w)/2-openvg.VGfloat(imw)/2, openvg.VGfloat(h)/2-openvg.VGfloat(imh)/2
			openvg.Img(x, y, img)
			openvg.End()
			time.Sleep(*delay)
		}
		if !*loop {
			break
		}
	}
}
Example #2
0
// nytheadlines retrieves data from the New York Times API, decodes and displays it.
func (d *display) nytheadlines(section string, thumb bool) {
	hdim := dimen{x: 0, y: 0, width: d.width, height: d.height / 2}
	r, err := netread(fmt.Sprintf(NYTfmt, section, NYTAPIkey))
	if err != nil {
		fmt.Fprintf(os.Stderr, "headline read error: %v\n", err)
		hdim.gerror(d.bgcolor, d.textcolor, "no headlines")
		return
	}
	defer r.Close()
	var data NYTHeadlines
	err = json.NewDecoder(r).Decode(&data)
	if err != nil {
		fmt.Fprintf(os.Stderr, "decode: %v\n", err)
		hdim.gerror(d.bgcolor, d.textcolor, "no headlines")
		return
	}
	x := d.width * 0.10
	y := d.height * 0.10
	thumbsize := int(d.height * 0.05)
	hdim.regionFill(d.bgcolor, d.textcolor)
	headsize := d.width / 80
	spacing := openvg.VGfloat(thumbsize)
	for i := len(data.Results) - 1; i >= 0; i-- {
		openvg.Text(x, y, fromHTML.Replace(data.Results[i].Title), "serif", int(headsize))
		if len(data.Results[i].Thumbnail) > 0 {
			img, imerr := netimage(data.Results[i].Thumbnail)
			if imerr != nil {
				continue
			}
			g := gift.New()
			g.Add(gift.Resize(0, thumbsize, gift.LanczosResampling))
			gift.Resize(thumbsize, thumbsize, gift.BoxResampling)
			resized := image.NewRGBA(g.Bounds(img.Bounds()))
			g.Draw(resized, img)
			openvg.Img(x-100, y-(spacing*0.25), resized)
		}
		y = y + spacing
	}
	openvg.Image(d.width*0.05, 15, 30, 30, "poweredby_nytimes_30a.png")
	openvg.End()
}
Example #3
0
func main() {
	var resize = flag.Bool("resize", false, "Resize image to fit the screen.")
	var bgcolor = flag.String("bg", "black", "Background color (named color or rgb(r,g,b)).")
	var fgcolor = flag.String("fg", "white", "text color (named color or rgb(r,g,b)).")
	var title = flag.String("t", "", "text annotation")
	var fontsize = flag.Float64("fp", 2.0, "fontsize %")
	var px = flag.Float64("px", 50, "x position %")
	var py = flag.Float64("py", 50, "y position %")
	var texty = flag.Float64("ty", 0, "text y %")
	var exit_code int
	defer func() {
		os.Exit(exit_code)
	}()
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, `usage: %s [ flags ] image-path

Set specified image as an overlay screen via OpenVG lib.
Default is to put this image to the center.

`, os.Args[0])
		flag.PrintDefaults()
		exit_code = 1
		return
	}

	flag.Parse()
	if flag.NArg() != 1 {
		fmt.Fprintf(os.Stderr, "Exactly one image-path argument must be specified.\n")
		flag.Usage()
		exit_code = 2
		return
	}

	openvg.SaveTerm()
	w, h := openvg.Init()
	openvg.RawTerm()
	defer openvg.Finish()
	defer openvg.RestoreTerm()

	img, err := getimage(flag.Args()[0], w, h, *resize)
	if err != nil {
		exit_code = 3
		return
	}
	ib := img.Bounds()
	imw, imh := ib.Max.X-ib.Min.X, ib.Max.Y-ib.Min.Y
	sig_chan := make(chan os.Signal, 1)
	signal.Notify(sig_chan, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGALRM)

	openvg.Start(w, h)
	openvg.BackgroundColor(*bgcolor)
	var x, y openvg.VGfloat
	if *px < 0 || *px > 100 {
		x = openvg.VGfloat(w)/2 - openvg.VGfloat(imw)/2
	} else {
		x = openvg.VGfloat(w)*openvg.VGfloat(*px/100) - openvg.VGfloat(imw)/2
	}

	if *py < 0 || *py > 100 {
		y = openvg.VGfloat(h)/2 - openvg.VGfloat(imh)/2
	} else {
		y = openvg.VGfloat(h)*openvg.VGfloat(*py/100) - openvg.VGfloat(imh)/2
	}
	openvg.Img(x, y, img)
	if len(*title) > 0 {
		var typ openvg.VGfloat
		fs := openvg.VGfloat(*fontsize/100.0) * openvg.VGfloat(w)
		if *texty == 0 {
			typ = y - fs*1.5
		} else {
			typ = openvg.VGfloat(h) * openvg.VGfloat(*texty/100)
		}
		openvg.FillColor(*fgcolor)
		openvg.TextMid(x+openvg.VGfloat(imw)/2, typ, *title, "sans", int(fs))
	}
	openvg.End()

	_ = <-sig_chan
}