Skip to content

tinywasm/screenshot

 
 

Repository files navigation

screenshot

Project Badges

=========

Go library to capture desktop screen. Fork of kbinani/screenshot.

  • Multiple display supported.
  • Supported GOOS: windows, darwin, linux, freebsd, openbsd, netbsd.
  • cgo free except for GOOS=darwin.

Install

go get github.com/tinywasm/screenshot

Example

package main

import (
	"fmt"
	"image/png"
	"os"

	"github.com/tinywasm/screenshot"
)

func main() {
	n := screenshot.NumActiveDisplays()

	for i := 0; i < n; i++ {
		bounds := screenshot.GetDisplayBounds(i)

		img, err := screenshot.CaptureRect(bounds)
		if err != nil {
			panic(err)
		}
		fileName := fmt.Sprintf("%d_%dx%d.png", i, bounds.Dx(), bounds.Dy())
		file, _ := os.Create(fileName)
		defer file.Close()
		png.Encode(file, img)

		fmt.Printf("#%d : %v \"%s\"\n", i, bounds, fileName)
	}
}

Output example:

$ go run main.go
#0 : (0,0)-(1280,800) "0_1280x800.png"
#1 : (-293,-1440)-(2267,0) "1_2560x1440.png"
#2 : (-1373,-1812)-(-293,108) "2_1080x1920.png"

Coordinate System

Y-axis is downward. The origin is the upper-left corner of the main display (same as Windows coordinate system).

License

MIT — original author: kbinani

About

Go library to capture desktop to image

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Go 99.6%
  • Other 0.4%