Documentation
¶
Index ¶
- Constants
- func Bool(v bool) *bool
- 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, params CropParams) (OpResult, error)
- func (c *Client) Info(ctx context.Context) (InfoResponse, error)
- func (c *Client) OptimizeGenerated(ctx context.Context, source string, params OptimizeGeneratedParams) (OpResult, 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 OptimizeGeneratedParams
- type Option
- type PipelineOperation
- type QualityReport
- type ResizeParams
- type UsageResponse
Constants ¶
const DefaultBaseURL = "https://api.pictomancer.ai"
const Version = "0.6.0"
Variables ¶
This section is empty.
Functions ¶
func Bool ¶ added in v0.6.0
Bool returns a pointer to v, for optional bool params such as OptimizeGeneratedParams.Strip.
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.
func (*Client) OptimizeGenerated ¶ added in v0.6.0
type CompressParams ¶
type CompressParams struct {
Format string `json:"format,omitempty"`
Q int `json:"q,omitempty"`
QualityTarget float64 `json:"quality_target,omitempty"`
Strip bool `json:"strip,omitempty"`
Autorot bool `json:"autorot,omitempty"`
Denoise int `json:"denoise,omitempty"`
Equalize bool `json:"equalize,omitempty"`
Sharpen bool `json:"sharpen,omitempty"`
Extra map[string]any `json:"-"`
Delivery *Delivery `json:"delivery,omitempty"`
}
CompressParams tunes the compress operation. Zero values are omitted. QualityTarget (0 < v <= 1) asks for the smallest file with SSIM >= target instead of a fixed Q; mutually exclusive with Q, requires an explicit Format (jpeg/webp/avif). The outcome lands in OpResult.Quality. Denoise (1-3), Equalize and Sharpen are opt-in enhancement modifiers.
type ConvertParams ¶
type ConvertParams struct {
Q int `json:"q,omitempty"`
QualityTarget float64 `json:"quality_target,omitempty"`
Strip bool `json:"strip,omitempty"`
Lossless bool `json:"lossless,omitempty"`
Effort *int `json:"effort,omitempty"`
Autorot bool `json:"autorot,omitempty"`
Denoise int `json:"denoise,omitempty"`
Equalize bool `json:"equalize,omitempty"`
Sharpen bool `json:"sharpen,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. QualityTarget (0 < v <= 1) asks for the smallest file with SSIM >= target instead of a fixed Q; mutually exclusive with Q and Lossless, only for jpeg/webp/avif targets. The outcome lands in OpResult.Quality. Denoise (1-3), Equalize and Sharpen are opt-in enhancement modifiers.
type CropParams ¶
type CropParams struct {
X *int `json:"x,omitempty"`
Y *int `json:"y,omitempty"`
Width *int `json:"width,omitempty"`
Height *int `json:"height,omitempty"`
Format string `json:"format,omitempty"`
Gravity string `json:"gravity,omitempty"`
Trim bool `json:"trim,omitempty"`
Threshold float64 `json:"threshold,omitempty"`
Autorot bool `json:"autorot,omitempty"`
Denoise int `json:"denoise,omitempty"`
Equalize bool `json:"equalize,omitempty"`
Sharpen bool `json:"sharpen,omitempty"`
Extra map[string]any `json:"-"`
Delivery *Delivery `json:"delivery,omitempty"`
}
CropParams tunes the crop operation. Three mutually exclusive modes: manual (X+Y+Width+Height), smart (Gravity + Width+Height, X/Y nil), trim (Trim=true, optional Threshold, X/Y/Width/Height nil). Autorot is valid in all three. X/Y/Width/Height are pointers because 0 is a legitimate corner distinct from unset; use Int to build them. Denoise (1-3), Equalize and Sharpen are opt-in enhancement modifiers.
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 ¶
type OpResult struct {
Bytes []byte
Receipt map[string]any
Quality *QualityReport
}
OpResult is the outcome of an image operation. Exactly one of Bytes and Receipt is populated: Bytes for inline delivery, Receipt (etag, sha256, bytes_written, ...) for put_url/callback deliveries. Quality accompanies either when the operation ran a quality_target search, nil otherwise.
type OptimizeGeneratedParams ¶ added in v0.6.0
type OptimizeGeneratedParams struct {
Format string `json:"format,omitempty"`
Q int `json:"q,omitempty"`
QualityTarget float64 `json:"quality_target,omitempty"`
MaxDimension int `json:"max_dimension,omitempty"`
Strip *bool `json:"strip,omitempty"`
Extra map[string]any `json:"-"`
Delivery *Delivery `json:"delivery,omitempty"`
}
OptimizeGeneratedParams tunes the optimize_generated operation. Zero values are omitted; the server defaults Format to webp and Strip to true, so Strip is a pointer (use Bool) to be able to send an explicit false.
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 QualityReport ¶ added in v0.3.0
QualityReport is the outcome of a quality_target SSIM search, parsed from the X-Pictomancer-Quality-* response headers. Absent (nil on OpResult) when no search ran: no quality_target requested, or the input already met the target and came back untouched (X-Pig-Billed: 0).
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"`
Width *int `json:"width,omitempty"`
Height *int `json:"height,omitempty"`
Gravity string `json:"gravity,omitempty"`
Autorot bool `json:"autorot,omitempty"`
Denoise int `json:"denoise,omitempty"`
Equalize bool `json:"equalize,omitempty"`
Sharpen bool `json:"sharpen,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. Fill mode: set Width+Height instead, optionally with Gravity (one of "attention", "entropy", "centre"; defaults to "attention" server-side). Denoise (1-3), Equalize and Sharpen are opt-in enhancement modifiers.
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).