camera

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package camera takes a photo, or picks one from the library, using the system's own screens. The photo comes back as JPEG bytes, so it works under `nimbus native dev` too, where your Go isn't on the phone.

nimbus native plugin add camera

p, err := camera.Take(ctx, camera.Options{MaxSize: 1600})
if plugin.IsCode(err, plugin.Cancelled) { return } // they backed out
filesystem.Write(ctx, filesystem.Data, "receipt.jpg", p.Data)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	MaxSize int     `json:"maxSize"` // its longer side, in pixels; 0 means 2000
	Quality float32 `json:"quality"` // JPEG, 0..1; 0 means 0.85
}

Options sizes the photo.

type Photo

type Photo struct {
	Data   []byte `json:"data"`   // the image, as a JPEG
	Width  int    `json:"width"`  // in pixels
	Height int    `json:"height"` // in pixels
}

Photo is a JPEG, turned the right way up.

func Pick

func Pick(ctx context.Context, o Options) (Photo, error)

Pick opens the photo library. It asks for no permission: the system shows the photos and the app only gets the one chosen.

func PickMany

func PickMany(ctx context.Context, o Options, limit int) ([]Photo, error)

PickMany opens the photo library to choose several. Like Pick, it asks for no permission. Photos come back in the order they were chosen.

func Take

func Take(ctx context.Context, o Options) (Photo, error)

Take opens the camera. It fails with plugin.Cancelled if they back out, and plugin.Unavailable where there's no camera, as on the iOS simulator.

type Video

type Video struct {
	Data    []byte  `json:"data"`    // the file
	Type    string  `json:"type"`    // its MIME type, such as "video/mp4"
	Seconds float64 `json:"seconds"` // how long it runs
}

Video is a video from the library, as it was recorded.

func PickVideo

func PickVideo(ctx context.Context, o VideoOptions) (Video, error)

PickVideo opens the library to choose a video. It comes back whole, through memory, so keep MaxBytes modest, and use a server upload for anything long.

type VideoOptions

type VideoOptions struct {
	MaxBytes int64 `json:"maxBytes"` // larger files fail; 0 means 50 MB
}

VideoOptions limits a video.

Jump to

Keyboard shortcuts

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