Help us shape the future of Go! Take the 2026 Go Developer Survey

gphoto2go

package module
v0.0.0-...-d3304d2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 6 Imported by: 1

README

gPhoto2-Go

A more Go idiomatic interface to the gPhoto2 library.

Warning

I'm not a great Golang programmer, so this could be a complete disaster. But, if you want to use the gPhoto2 library and you'd prefer to avoid sticking cgo references all over your main Go program, this library might help.

I'm also not a great C programmer, having grown up with garbage collectors and other niceties. Therefore, this library will be riddled with memory leaks. I would appreciate any help in making it more memory efficient.

Installation

go get github.com/micahwedemeyer/gphoto2go

Requirements

You will also need libgphoto2 installed. If you are on Mac OS X, I recommend installing it with homebrew.

brew install libgphoto2

This should now compile by itself thanks to this // #cgo pkg-config: libgphoto2

Usage

The main goal with this library is to present a Go-friendly interface to the C methods of gPhoto2

Camera Initializing
camera := new(gphoto2go.Camera)
err := camera.Init()

This will create a new Camera struct and intitialize it, which prompts gphoto2 to auto-detect any connected USB cameras.

Taking a Photo
camera.TriggerCapture()

This will trigger the camera.

Downloading the Photos from the Camera
folders := camera.RListFolders("/")
for _, folder := range folders {
    files, _ := camera.ListFiles(folder)
    for _, fileName := range files {
        cameraFileReader := camera.FileReader(folder, fileName)
        fileWriter := os.Create("/tmp/" + fileName)
        io.Copy(fileWriter, cameraFileReader)

        // Important, since there is memory used in the transfer that needs to be freed up
        cameraFileReader.Close()
    }
}
Interpreting errors

Most of the functions will return an error code. If it is less than zero, that means an error has occurred. The library can translate the error integer into a human readable string.

err := camera.TriggerCapture()
if err < 0 {
    fmt.Printf(gphoto2go.CameraResultToString(err))
}

Documentation

Index

Constants

View Source
const (
	CAPTURE_IMAGE = C.GP_CAPTURE_IMAGE
	CAPTURE_MOVIE = C.GP_CAPTURE_MOVIE
	CAPTURE_SOUND = C.GP_CAPTURE_SOUND
)

Variables

This section is empty.

Functions

func CameraResultToString

func CameraResultToString(err C.int) string

Types

type Camera

type Camera struct {
	// contains filtered or unexported fields
}

func (*Camera) AsyncWaitForEvent

func (c *Camera) AsyncWaitForEvent(timeout int) chan *CameraEvent

func (*Camera) Cancel

func (c *Camera) Cancel()

func (*Camera) CapturePreview

func (c *Camera) CapturePreview() (cf CameraFile, err error)

func (*Camera) DeleteFile

func (c *Camera) DeleteFile(folder, file string) error

func (*Camera) Exit

func (c *Camera) Exit() error

func (*Camera) FileReader

func (c *Camera) FileReader(folder string, fileName string) (io.ReadCloser, error)

func (*Camera) GetAbilities

func (c *Camera) GetAbilities() (C.CameraAbilities, error)

func (*Camera) GetConfig

func (c *Camera) GetConfig() (*CameraWidget, error)

func (*Camera) Init

func (c *Camera) Init() error

func (*Camera) ListFiles

func (c *Camera) ListFiles(folder string) ([]string, error)

func (*Camera) ListFolders

func (c *Camera) ListFolders(folder string) ([]string, error)

func (*Camera) Model

func (c *Camera) Model() (string, error)

func (*Camera) RListFolders

func (c *Camera) RListFolders(folder string) ([]string, error)

func (*Camera) SetConfig

func (c *Camera) SetConfig(w *CameraWidget) error

func (*Camera) TriggerCapture

func (c *Camera) TriggerCapture() error

func (*Camera) TriggerCaptureToFile

func (c *Camera) TriggerCaptureToFile() (CameraFilePath, error)

type CameraEvent

type CameraEvent struct {
	Type   CameraEventType
	Folder string
	File   string
}

type CameraEventType

type CameraEventType int
const (
	EventUnknown   CameraEventType = C.GP_EVENT_UNKNOWN
	EventTimeout   CameraEventType = C.GP_EVENT_TIMEOUT
	EventFileAdded CameraEventType = C.GP_EVENT_FILE_ADDED
)

type CameraFile

type CameraFile struct {
	// contains filtered or unexported fields
}

func (*CameraFile) Close

func (cf *CameraFile) Close() error

type CameraFilePath

type CameraFilePath struct {
	Name   string
	Folder string
}

type CameraWidget

type CameraWidget struct {
	// contains filtered or unexported fields
}

func (*CameraWidget) Free

func (w *CameraWidget) Free()

func (*CameraWidget) GetChildrenByName

func (w *CameraWidget) GetChildrenByName(name string) (*CameraWidget, error)

func (*CameraWidget) SetValue

func (w *CameraWidget) SetValue(v interface{}) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL