Documentation
¶
Overview ¶
Package pictrs provides an API wrapper for pict-rs: https://git.asonix.dog/asonix/pict-rs.
Index ¶
- Variables
- func Value[T any](v T) *T
- type Client
- func (c *Client) BlurHashImage(ctx context.Context, file string) (string, error)
- func (c *Client) DeleteImage(ctx context.Context, file, deleteToken string) error
- func (c *Client) Healthz(ctx context.Context) error
- func (c *Client) OriginalImage(ctx context.Context, file string) (FileDownloader, error)
- func (c *Client) OriginalImageDetails(ctx context.Context, file string) (UploadedFileDetails, error)
- func (c *Client) ProcessedImage(ctx context.Context, file string, ext Extension, ...) (FileDownloader, error)
- func (c *Client) ProcessedImageDetails(ctx context.Context, file string, ext Extension, ...) (UploadedFileDetails, error)
- func (c *Client) UploadImages(ctx context.Context, files []FileUploader, params UploadParams) ([]UploadedFile, error)
- func (c *Client) UploadImagesBackgrounded(ctx context.Context, files []FileUploader, params UploadParams) ([]string, error)
- func (c *Client) UploadRemoteImage(ctx context.Context, remoteURL string) (*UploadedFile, error)
- func (c *Client) UploadRemoteImageBackgrounded(remoteURL string) (string, error)
- func (c *Client) WaitForUpload(ctx context.Context, uploadID string) (*UploadedFile, error)
- func (c *Client) WithHTTPClient(client *http.Client) *Client
- func (c *Client) WithLogger(logger *slog.Logger) *Client
- type CropTransformation
- type Extension
- type FileDownloader
- type FileFormat
- type FileUploader
- type ResizeTransformation
- type ServerError
- type Transformations
- type UploadParams
- type UploadedFile
- type UploadedFileDetails
Constants ¶
This section is empty.
Variables ¶
var ErrNoExtension = errors.New("no extension provided")
ErrNoExtension indicates that no file extension was provided when it was expected.
Functions ¶
Types ¶
type Client ¶
Client represents a client for interacting with the pict-rs API.
func (*Client) BlurHashImage ¶
BlurHashImage retrieves the BlurHash representation of the image file from the pict-rs server.
BlurHash is described in https://blurha.sh/.
func (*Client) DeleteImage ¶
DeleteImage deletes an image file from the pict-rs server using the provided delete token associated with the file.
func (*Client) OriginalImage ¶
OriginalImage retrieves the full resolution image file from the pict-rs server. The returned io.ReadCloser will contain the original image data.
func (*Client) OriginalImageDetails ¶
func (c *Client) OriginalImageDetails(ctx context.Context, file string) (UploadedFileDetails, error)
OriginalImageDetails retrieves the details of the original image file from the pict-rs server.
func (*Client) ProcessedImage ¶
func (c *Client) ProcessedImage(ctx context.Context, file string, ext Extension, transformations Transformations) (FileDownloader, error)
ProcessedImage retrieves a processed version of the image file from the pict-rs server. If [ext] is empty, it'll be taken from [file], otherwise it's an error.
func (*Client) ProcessedImageDetails ¶
func (c *Client) ProcessedImageDetails(ctx context.Context, file string, ext Extension, transformations Transformations) (UploadedFileDetails, error)
ProcessedImageDetails retrieves the details of a processed image file from the pict-rs server. If [ext] is empty, it'll be taken from [file], otherwise it's an error.
func (*Client) UploadImages ¶
func (c *Client) UploadImages(ctx context.Context, files []FileUploader, params UploadParams) ([]UploadedFile, error)
UploadImages uploads files to the pict-rs server.
func (*Client) UploadImagesBackgrounded ¶
func (c *Client) UploadImagesBackgrounded(ctx context.Context, files []FileUploader, params UploadParams) ([]string, error)
UploadImagesBackgrounded uploads files to the pict-rs server, but the files are processed in the background, allowing for immediate response. It returns a list of upload IDs.
func (*Client) UploadRemoteImage ¶
UploadRemoteImage uploads the image at the remote URL to the pict-rs server.
func (*Client) UploadRemoteImageBackgrounded ¶
UploadRemoteImageBackgrounded uploads the image at the remote URL to the pict-rs server, but the upload is processed in the background. It returns the upload ID for later retrieval.
func (*Client) WaitForUpload ¶
WaitForUpload waits for a backgrounded upload to complete and returns the result from the pict-rs server. If the file is not yet available and the waiting has timed out, it will be retried until the context is done.
func (*Client) WithHTTPClient ¶
WithHTTPClient sets the HTTP client to use for requests.
type CropTransformation ¶
CropTransformation produces a cropped version of the image with the given width and height. The resulting crop is centered on the original image.
func (CropTransformation) MarshalText ¶
func (c CropTransformation) MarshalText() ([]byte, error)
func (CropTransformation) String ¶
func (c CropTransformation) String() string
func (*CropTransformation) UnmarshalText ¶
func (c *CropTransformation) UnmarshalText(b []byte) error
type Extension ¶
type Extension string
Extension represents a file extension, such as ".jpg" or ".png".
const ( InheritExtension Extension = "" APNGExtension Extension = ".apng" AVIFExtension Extension = ".avif" GIFExtension Extension = ".gif" JPGExtension Extension = ".jpg" JPEGExtension Extension = ".jpg" JXLExtension Extension = ".jxl" PNGExtension Extension = ".png" WebPExtension Extension = ".webp" )
type FileDownloader ¶
type FileDownloader interface { io.ReadCloser ContentType() string ContentLength() int64 // -1 if unknown }
FileDownloader extends io.ReadCloser to represent a reader for downloading image data while also querying its metadata.
type FileFormat ¶
type FileFormat string
FileFormat is the format of the uploaded file.
const ( ImageFormat FileFormat = "Image" VideoFormat FileFormat = "Video" AnimationFormat FileFormat = "Animation" )
type FileUploader ¶
FileUploader is a file that is to be uploaded to the pict-rs server. It must have a Reader and optionally a Name.
type ResizeTransformation ¶
ResizeTransformation represents a resize transformation for an image. If area is false, then the image will be resized to [Size]x[Size] pixels, otherwise the image will be resized such that the area is at most [Size] pixels.
func (ResizeTransformation) MarshalText ¶
func (r ResizeTransformation) MarshalText() ([]byte, error)
func (ResizeTransformation) String ¶
func (r ResizeTransformation) String() string
func (*ResizeTransformation) UnmarshalText ¶
func (r *ResizeTransformation) UnmarshalText(b []byte) error
type ServerError ¶
type ServerError struct { Code string `json:"code,omitempty"` Message string `json:"msg"` HTTPStatus int `json:"-"` }
ServerError represents an error response from the pict-rs server.
func (*ServerError) Error ¶
func (e *ServerError) Error() string
type Transformations ¶
type Transformations struct { Identity bool `schema:"identity,omitempty"` Blur *float64 `schema:"blur,omitempty"` Thumbnail *int `schema:"thumbnail,omitempty"` Resize *ResizeTransformation `schema:"resize,omitempty"` Crop *CropTransformation `schema:"crop,omitempty"` }
Transformations represents a set of transformations that can be applied to an image.
type UploadParams ¶
type UploadParams struct { MaxWidth *int `schema:"max_width,omitempty"` MaxHeight *int `schema:"max_height,omitempty"` MaxArea *int `schema:"max_area,omitempty"` MaxFrameCount *int `schema:"max_frame_count,omitempty"` MaxFileSizeMB *int `schema:"max_file_size,omitempty"` AllowImage *bool `schema:"allow_image,omitempty"` AllowAnimation *bool `schema:"allow_animation,omitempty"` AllowVideo *bool `schema:"allow_video,omitempty"` }
UploadParams contains arguments for
type UploadedFile ¶
type UploadedFile struct { DeleteToken string `json:"delete_token"` File string `json:"file"` Details UploadedFileDetails `json:"details"` }
UploadedFile is a file that has been uploaded to the pict-rs server.
type UploadedFileDetails ¶
type UploadedFileDetails struct { BlurHash string `json:"blurhash"` Width int `json:"width"` Height int `json:"height"` ContentType string `json:"content_type"` CreatedAt time.Time `json:"created_at"` Format FileFormat `json:"format"` }
UploadedFileDetails contains details about an uploaded file.