pluto

package module
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: CC0-1.0 Imports: 37 Imported by: 1

README

Pluto Image Service

Pluto Image Service is a lightweight, high-performance image processing and serving service built in Go. It supports dynamic image resizing, caching, and format conversion via a simple HTTP API.

Features

  • Resize, crop, and convert images on the fly
  • Caching for fast image delivery
  • Easy-to-use HTTP API
  • Built with Go for speed and efficiency

Usage

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupImages added in v0.4.3

func CleanupImages(ctx context.Context) error

func CleanupPlutoCache added in v0.2.0

func CleanupPlutoCache(imageUuid string) (int, error)

Delete cache files

func CleanupPlutoImage added in v0.2.0

func CleanupPlutoImage(imageFileName string) (bool, error)

Delete original image file

func CropWithFocus added in v0.1.8

func CropWithFocus(
	img image.Image,
	targetRatio float32,
	focusX, focusY float32,
	targetW, targetH int,
) image.Image

CropWithFocus crops an image to a target aspect ratio and optionally resizes, centered on the focus point, while preserving alpha transparency.

func CropWithFocusWithoutAlpha added in v0.3.0

func CropWithFocusWithoutAlpha(
	img image.Image,
	targetRatio float32,
	focusX, focusY float32,
	targetW, targetH int,
) image.Image

func DecodeFloat32FromPath added in v0.1.8

func DecodeFloat32FromPath(s string) (float32, error)

DecodeFloat32FromPath reverses the encoding back to float32.

func DeleteCacheTx added in v0.2.0

func DeleteCacheTx(
	ctx context.Context,
	tx pgx.Tx,
	imageUuid string,
) (deletedFilesCount int64, err error)

Deletes cache DB entries, return number of affected rows

func DeleteFilesWithPrefix added in v0.2.0

func DeleteFilesWithPrefix(dir string, prefix string) (int, error)

DeleteFilesWithPrefix deletes all files in a directory that start with the given prefix. Returns the number of deleted files and an error (if any).

func DeleteImageTx added in v0.2.0

func DeleteImageTx(
	ctx context.Context,
	tx pgx.Tx,
	imageUuid string,
) (deletedFileName string, cacheRows int64, err error)

Deletes image + cache DB entries, returns filename to delete from disk

func EncodeFloat32ForPath added in v0.1.8

func EncodeFloat32ForPath(f float32) string

EncodeFloat32ForPath converts a float32 into a safe ASCII filename string. Output contains only [0-9a-f] and is exactly 8 characters long.

func FloatPtrEqual added in v0.2.0

func FloatPtrEqual(a, b *float64) bool

func GetImageFocusTx added in v0.2.0

func GetImageFocusTx(
	ctx context.Context,
	tx pgx.Tx,
	imageUuid string,
) (focusX *float64, focusY *float64, err error)

GetImageFocus returns focus_x and focus_y for an image

func GetImageUuidByByContext added in v0.4.3

func GetImageUuidByByContext(
	gc *gin.Context,
	context string,
	contextUuid string,
	identifier string,
) (string, bool)

func GetQueryBoolDefault added in v0.3.0

func GetQueryBoolDefault(gc *gin.Context, key string, def bool) (bool, bool)

func GetQueryInt added in v0.1.8

func GetQueryInt(gc *gin.Context, key string) (int, bool)

func GetQueryIntDefault added in v0.1.8

func GetQueryIntDefault(gc *gin.Context, key string, def int) (int, bool)

func ParamInt added in v0.1.4

func ParamInt(gc *gin.Context, key string) (int, bool)

func ParseAspectRatio

func ParseAspectRatio(s string) (float32, error)

func RemoveFile added in v0.2.0

func RemoveFile(path string) error

RemoveFile deletes a file at the given path. Returns an error if the file cannot be deleted.

func ResizeToWidth

func ResizeToWidth(img image.Image, width int, ratio string) image.Image

Types

type ApiTxError added in v0.3.0

type ApiTxError struct {
	Code int
	Err  error
}

func ApiErrForbidden added in v0.3.0

func ApiErrForbidden(msg string, args ...any) *ApiTxError

Specialized helpers

func ApiErrInternal added in v0.3.0

func ApiErrInternal(msg string, args ...any) *ApiTxError

func ApiErrNotFound added in v0.3.0

func ApiErrNotFound(msg string, args ...any) *ApiTxError

func NewApiTxError added in v0.3.0

func NewApiTxError(code int, msg string, args ...any) *ApiTxError

func WithTransaction added in v0.3.0

func WithTransaction(ctx context.Context, db *pgxpool.Pool, fn func(tx pgx.Tx) *ApiTxError) *ApiTxError

func (*ApiTxError) Error added in v0.3.0

func (e *ApiTxError) Error() string

type CacheEntry added in v0.3.0

type CacheEntry struct {
	Id        int       `json:"id"`
	Receipt   string    `json:"receipt"`
	ImageId   *int      `json:"image_id,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	MimeType  *string   `json:"mime_type,omitempty"`
}

type Config

type Config struct {
	BaseApiUrl            string `json:"base_api_url"`
	DbHost                string `json:"db_host"`
	DbPort                int    `json:"db_port"`
	DbUser                string `json:"db_user"`
	DbPassword            string `json:"db_password"`
	DbName                string `json:"db_name"`
	DbSchema              string `json:"db_schema"`
	SSLMode               string `json:"ssl_mode"`
	PlutoVerbose          bool   `json:"pluto_verbose"`
	PlutoRoute            string `json:"pluto_route"`
	PlutoImageDir         string `json:"pluto_image_dir"`
	PlutoCacheDir         string `json:"pluto_cache_dir"`
	PlutoMaxImageSize     int64  `json:"pluto_max_image_size"`
	PlutoMaxImagePx       int    `json:"pluto_max_image_px"`
	PlutoDefaultQuality   int    `json:"pluto_default_quality"`
	PlutoDefaultImageType string `json:"pluto_default_image_type"`
}

Config holds database configuration details

func DefaultConfig added in v0.2.0

func DefaultConfig() Config

func (Config) Print

func (config Config) Print()

type DeleteImageResult added in v0.3.0

type DeleteImageResult struct {
	HttpStatus        int
	Message           string
	FileRemovedFlag   bool
	CacheFilesRemoved int
	ImageUuid         string
}

DeleteImageResult mirrors UpsertImageResult

func DeleteImage added in v0.3.0

func DeleteImage(
	gc *gin.Context,
	context string,
	contextUuid string,
	identifier string,
	postCallback TxFunc,
) (DeleteImageResult, error)

DeleteImage deletes an image by context/contextId/identifier

type ImageCleanupResult added in v0.2.0

type ImageCleanupResult struct {
	CacheFilesRemoved int
	ImageFileRemoved  bool
}

func CleanupPlutoImageFiles added in v0.2.0

func CleanupPlutoImageFiles(imageUuid string, fileName string) (*ImageCleanupResult, error)

type ImageIdentifierValidator added in v0.4.0

type ImageIdentifierValidator func(string) bool

type ImageMeta added in v0.3.0

type ImageMeta struct {
	Uuid        *string        `json:"uuid"`
	FileName    *string        `json:"file_name,omitempty"`
	Width       *int           `json:"width,omitempty"`
	Height      *int           `json:"height,omitempty"`
	MimeType    *string        `json:"mime_type,omitempty"`
	AltText     *string        `json:"alt_text,omitempty"`
	Description *string        `json:"description,omitempty"`
	License     *string        `json:"license,omitempty"`
	Exif        map[string]any `json:"exif,omitempty"`
	Expiration  *string        `json:"expiration_date,omitempty"`
	Creator     *string        `json:"creator,omitempty"`
	Copyright   *string        `json:"copyright,omitempty"`
	FocusX      *float64       `json:"focus_x,omitempty"`
	FocusY      *float64       `json:"focus_y,omitempty"`
}

type ImageRefresherCallback added in v0.4.0

type ImageRefresherCallback func(entity string, uuids []string) TxFunc

type Pluto

type Pluto struct {
	Config   Config
	Verbose  bool
	DbPool   *pgxpool.Pool
	DbSchema string
}
var PlutoInstance *Pluto

func Initialize added in v0.1.3

func Initialize(configFilePath string, pool *pgxpool.Pool, verbose bool) (*Pluto, error)

New creates and initializes a new Pluto instance

func (*Pluto) Log

func (pluto *Pluto) Log(msg string)

func (*Pluto) RegisterRoutes

func (pluto *Pluto) RegisterRoutes(rg *gin.RouterGroup, middlewares ...gin.HandlerFunc)

type TxFunc added in v0.3.0

type TxFunc func(ctx context.Context, tx pgx.Tx) error

type UpsertImageResult added in v0.3.0

type UpsertImageResult struct {
	HttpStatus        int
	Message           string
	FileRemovedFlag   bool
	CacheFilesRemoved int
	ImageUuid         string
}

func UpsertImage added in v0.3.0

func UpsertImage(
	gc *gin.Context,
	context string,
	contextUuid string,
	identifier string,
	fileNamePrefix *string,
	userUuid string,
	postCallback TxFunc,
) (UpsertImageResult, error)

Jump to

Keyboard shortcuts

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