pluto

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: CC0-1.0 Imports: 28 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

Run the service:

go run main.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupPlutoCache added in v0.2.0

func CleanupPlutoCache(imageId int) (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

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,
	imageID int,
) (cacheRows 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,
	imageId int,
) (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 GenerateImageFilename

func GenerateImageFilename(originalName string) (string, error)

GenerateImageFilename returns a securely generated random filename that preserves the original file's extension.

It creates a 128-bit (16-byte) cryptographically secure random identifier, encodes it as a 32-character hexadecimal string, and appends the original file extension (e.g. ".jpg", ".png") from the input filename.

This function is suitable for generating unique, unpredictable image filenames for uploaded files.

Example:

"cat.jpg" => "f3ab7c54c8a44f01bd1182d4a57c121a.jpg"

Parameters:

originalName - the original filename, from which the extension will be preserved.

Returns:

  • A string containing the generated filename (randomHex + original extension).
  • An error if the secure random number generation fails.

func GetImageFocusTx added in v0.2.0

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

GetImageFocus returns focus_x and focus_y for an image

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 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"`
	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 ImageCleanupResult added in v0.2.0

type ImageCleanupResult struct {
	CacheFilesRemoved int
	ImageFileRemoved  bool
}

func CleanupPlutoImageFiles added in v0.2.0

func CleanupPlutoImageFiles(
	imageId int,
	fileName string,
) (*ImageCleanupResult, error)

type ImageMetadata

type ImageMetadata struct {
	UserID    string
	License   string
	CreatedBy string
	Copyright string
	AltText   string
	FocusX    float64
	FocusY    float64
}

type Param

type Param struct {
	Exist bool
	Value string
}

type Pluto

type Pluto struct {
	Config  Config
	Verbose bool
	DbPool  *pgxpool.Pool
}
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)

Jump to

Keyboard shortcuts

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