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

imageoutput

package
v1.44.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package imageoutput saves base64 Images API responses to local image files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckName

func CheckName(ctx context.Context, directory, normalizedName string) error

CheckName probes actual filesystem limits before requesting images. The directory must already exist and the name must already be normalized. Empty names use the short timestamp fallback and do not need a separate probe.

func NameFromPrompt

func NameFromPrompt(prompt string) string

NameFromPrompt makes a short filename stem from the description. It retains Unicode letters, numbers and their combining marks, dropping only an initial English article. The result contains no extension or path components. Empty results let the caller retain its usual timestamp fallback.

func NormalizeName

func NormalizeName(name string) (string, error)

NormalizeName strips one familiar image suffix. The response's actual format supplies the extension when saving; names may not contain path components.

func ResolveDirectory

func ResolveDirectory(requested string) (string, error)

ResolveDirectory returns an absolute, writable output directory. It creates the default directory, but requires a caller-selected directory to exist.

func ValidateName

func ValidateName(name string) error

ValidateName checks a filename stem against supported platforms' restrictions.

Types

type SavedImage added in v1.26.0

type SavedImage struct {
	Path   string
	SHA256 [sha256.Size]byte
}

SavedImage identifies the bytes successfully written by the save operation. SHA256 lets an optional preview verify a reopened file before decoding it.

func SaveResponse

func SaveResponse(ctx context.Context, raw []byte, directory string, name ...string) (saved []SavedImage, err error)

SaveResponse saves every base64 image, returning completed files in response order even if siblings fail. Only incomplete files are removed. Cancellation stops the batch. URL responses are not downloaded. An omitted name uses local date/time; collisions receive -2, -3, and subsequent suffixes.

Jump to

Keyboard shortcuts

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