Documentation
¶
Index ¶
- Constants
- func Int(v int) *int
- func SourceFromBytes(data []byte) string
- func SourceFromPath(path string) (string, error)
- func SourceFromReader(r io.Reader) (string, error)
- type APIError
- type AnalyzeResponse
- type Client
- func (c *Client) Analyze(ctx context.Context, source string) (AnalyzeResponse, error)
- func (c *Client) Compress(ctx context.Context, source string, params CompressParams) (OpResult, error)
- func (c *Client) Convert(ctx context.Context, source, format string, params ConvertParams) (OpResult, error)
- func (c *Client) Crop(ctx context.Context, source string, x, y, width, height int, params CropParams) (OpResult, error)
- func (c *Client) Info(ctx context.Context) (InfoResponse, error)
- func (c *Client) Pipeline(ctx context.Context, source string, operations []PipelineOperation, ...) (OpResult, error)
- func (c *Client) Resize(ctx context.Context, source string, params ResizeParams) (OpResult, error)
- func (c *Client) Usage(ctx context.Context) (UsageResponse, error)
- type CompressParams
- type ConvertParams
- type CropParams
- type Delivery
- type DeliveryOption
- type FormatOption
- type FormatSpec
- type InfoResponse
- type OpResult
- type Option
- type PipelineOperation
- type ResizeParams
- type UsageResponse
Constants ¶
const DefaultBaseURL = "https://api.pictomancer.ai"
const Version = "0.2.0"
Variables ¶
This section is empty.
Functions ¶
func SourceFromBytes ¶ added in v0.2.0
SourceFromBytes encodes in-memory image bytes as the raw base64 source string the API accepts.
func SourceFromPath ¶ added in v0.2.0
SourceFromPath reads a local image file and encodes it.
Types ¶
type AnalyzeResponse ¶
type AnalyzeResponse struct {
SizeBytes int64 `json:"size_bytes"`
}
AnalyzeResponse is the metadata of a fetched image. Always free.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a thin client for the Pictomancer.ai REST API.
type CompressParams ¶
type CompressParams struct {
Format string `json:"format,omitempty"`
Q int `json:"q,omitempty"`
Strip bool `json:"strip,omitempty"`
Extra map[string]any `json:"-"`
Delivery *Delivery `json:"delivery,omitempty"`
}
CompressParams tunes the compress operation. Zero values are omitted.
type ConvertParams ¶
type ConvertParams struct {
Q int `json:"q,omitempty"`
Strip bool `json:"strip,omitempty"`
Lossless bool `json:"lossless,omitempty"`
Effort *int `json:"effort,omitempty"`
Extra map[string]any `json:"-"`
Delivery *Delivery `json:"delivery,omitempty"`
}
ConvertParams tunes the convert operation. Zero values are omitted. Effort is a pointer because 0 is a valid AVIF encoder value distinct from unset (API default 2); use Int to build it.
type CropParams ¶
type CropParams struct {
Format string `json:"format,omitempty"`
Extra map[string]any `json:"-"`
Delivery *Delivery `json:"delivery,omitempty"`
}
CropParams tunes the crop operation. Zero values are omitted.
type Delivery ¶
type Delivery struct {
Mode string `json:"mode"`
PutURL string `json:"put_url,omitempty"`
CallbackURL string `json:"callback_url,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Secret string `json:"secret,omitempty"`
}
Delivery selects where the optimized bytes go. Inline (the default) returns them in the response; put_url uploads to a customer-signed presigned PUT URL; callback_url POSTs them to a customer endpoint with an X-Pig-Sha256 integrity header and optional HMAC signature.
func NewCallbackDelivery ¶
func NewCallbackDelivery(url string, opts ...DeliveryOption) *Delivery
func NewInlineDelivery ¶
func NewInlineDelivery() *Delivery
func NewPutURLDelivery ¶
func NewPutURLDelivery(url string, opts ...DeliveryOption) *Delivery
type DeliveryOption ¶
type DeliveryOption func(*Delivery)
func WithDeliveryHeaders ¶
func WithDeliveryHeaders(headers map[string]string) DeliveryOption
WithDeliveryHeaders forwards extra signed headers (x-amz-*, x-goog-*, x-ms-*) that the presigned URL or endpoint expects.
func WithDeliverySecret ¶
func WithDeliverySecret(secret string) DeliveryOption
WithDeliverySecret enables HMAC-SHA256 signing of callback bodies: the request carries X-Pig-Signature: sha256=<hex>, recomputable on the receiving end with the same secret. Used per request, never stored.
type FormatOption ¶
type FormatOption struct {
Name string `json:"name"`
Kind string `json:"kind"`
DefaultStr string `json:"default_str"`
Description string `json:"description"`
Min *int `json:"min,omitempty"`
Max *int `json:"max,omitempty"`
}
FormatOption describes one tunable knob of an output format.
type FormatSpec ¶
type FormatSpec struct {
ID string `json:"id"`
Suffix string `json:"suffix"`
Options []FormatOption `json:"options"`
}
FormatSpec describes one output format (id, file suffix, options).
type InfoResponse ¶
type InfoResponse struct {
Formats []FormatSpec `json:"formats"`
}
InfoResponse lists the supported output formats and their options.
type OpResult ¶
OpResult is the outcome of an image operation. Exactly one field is populated: Bytes for inline delivery, Receipt (etag, sha256, bytes_written, ...) for put_url/callback deliveries.
type Option ¶
type Option func(*Client)
func WithAPIKey ¶
WithAPIKey sets the Bearer token (Authorization: Bearer ...).
func WithAdapter ¶
WithAdapter swaps the HTTP backend (e.g. withttp.Fasthttp()). Defaults to net/http.
func WithAgentWallet ¶
WithAgentWallet sets the X-Agent-Wallet identity for x402 tracking.
func WithBaseURL ¶
WithBaseURL overrides the default https://api.pictomancer.ai.
type PipelineOperation ¶
type PipelineOperation struct {
Type string `json:"type"`
Params map[string]string `json:"params"`
}
PipelineOperation is one step of a multi-op pipeline. Params values are strings, matching the API contract (e.g. {"scale": "0.5"}).
type ResizeParams ¶
type ResizeParams struct {
Scale float64 `json:"scale,omitempty"`
ScaleX float64 `json:"scale_x,omitempty"`
ScaleY float64 `json:"scale_y,omitempty"`
Format string `json:"format,omitempty"`
Extra map[string]any `json:"-"`
Delivery *Delivery `json:"delivery,omitempty"`
}
ResizeParams tunes the resize operation. Zero values are omitted. Use Scale for uniform scaling or ScaleX/ScaleY for independent axes.
type UsageResponse ¶
type UsageResponse struct {
Identity string `json:"identity"`
RequestsUsed int `json:"requests_used"`
FreeTierLimit int `json:"free_tier_limit"`
FreeRemaining int `json:"free_remaining"`
IsFree bool `json:"is_free"`
}
UsageResponse reports request usage and free tier status for the caller's identity (wallet header or IP fallback).