mbr/elm-camera/1.1.0

NOTE: the latest version is 1.3.0

Camera.Snapshot

Types for working with PNG snapshots.

Snapshot data stays in the browser rather than passing through Elm ports. Elm receives Metadata with an opaque Handle, which can be used to create a URL for showing or downloading the PNG.

The browser keeps each successful snapshot until its handle is passed to Camera.discardSnapshot, or until the camera runtime shuts down. Dropping the handle from your Elm model, removing an image from the page, or closing the camera does not release the snapshot. Camera.discardSnapshot releases both the PNG and any URLs created for it. A browser integration that retains the immutable Blob returned by cameraRuntime.snapshotBlob(handle) can extend the underlying data's lifetime beyond that operation.

Identity and metadata

type alias Handle =
SnapshotHandle

A handle for a PNG snapshot stored in the browser.

The snapshot remains stored until this handle is passed to Camera.discardSnapshot or the runtime shuts down. Handles are never reused.

type alias Url =
SnapshotUrl

A browser URL created for showing or downloading a snapshot.

type alias Metadata =
{ handle : Handle
, width : Int
, height : Int
, mimeType : String
, byteSize : Int
}

Information about a PNG snapshot stored in the browser.

byteSize is the size of the encoded PNG.

Capture options

type alias Options =
{ crop : Maybe Crop
, width : Maybe Int
, height : Maybe Int
}

Options for cropping and resizing a PNG snapshot.

The crop uses pixels from the camera image. width and height resize the result before it is encoded. When only one dimension is given, the original aspect ratio is preserved.

type alias Crop =
{ x : Int
, y : Int
, width : Int
, height : Int
}

A rectangular part of the camera image, measured in pixels.

defaultOptions : Options

Options that keep the complete camera frame at its original size.

Browser integrations

encodeHandle : Handle -> Value

Encode a snapshot handle for an application-owned browser integration.

handleDecoder : Decoder Handle

Decode a snapshot handle returned by an application-owned browser integration.

Object URLs

urlToString : Url -> String

Get the string value of a snapshot URL.

The URL works until its snapshot is discarded and should not be stored permanently.