Documentation
¶
Index ¶
- func CleanupPlutoCache(imageId int) (int, error)
- func CleanupPlutoImage(imageFileName string) (bool, error)
- func CropWithFocus(img image.Image, targetRatio float32, focusX, focusY float32, ...) image.Image
- func DecodeFloat32FromPath(s string) (float32, error)
- func DeleteCacheTx(ctx context.Context, tx pgx.Tx, imageID int) (cacheRows int64, err error)
- func DeleteFilesWithPrefix(dir string, prefix string) (int, error)
- func DeleteImageTx(ctx context.Context, tx pgx.Tx, imageId int) (deletedFileName string, cacheRows int64, err error)
- func EncodeFloat32ForPath(f float32) string
- func FloatPtrEqual(a, b *float64) bool
- func GenerateImageFilename(originalName string) (string, error)
- func GetImageFocusTx(ctx context.Context, tx pgx.Tx, imageID int) (focusX *float64, focusY *float64, err error)
- func GetQueryInt(gc *gin.Context, key string) (int, bool)
- func GetQueryIntDefault(gc *gin.Context, key string, def int) (int, bool)
- func ParamInt(gc *gin.Context, key string) (int, bool)
- func ParseAspectRatio(s string) (float32, error)
- func RemoveFile(path string) error
- func ResizeToWidth(img image.Image, width int, ratio string) image.Image
- type Config
- type ImageCleanupResult
- type ImageMetadata
- type Param
- type Pluto
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanupPlutoCache ¶ added in v0.2.0
Delete cache files
func CleanupPlutoImage ¶ added in v0.2.0
Delete original image file
func CropWithFocus ¶ added in v0.1.8
func DecodeFloat32FromPath ¶ added in v0.1.8
DecodeFloat32FromPath reverses the encoding back to float32.
func DeleteCacheTx ¶ added in v0.2.0
Deletes cache DB entries, return number of affected rows
func DeleteFilesWithPrefix ¶ added in v0.2.0
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
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 GenerateImageFilename ¶
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 GetQueryIntDefault ¶ added in v0.1.8
func ParseAspectRatio ¶
func RemoveFile ¶ added in v0.2.0
RemoveFile deletes a file at the given path. Returns an error if the file cannot be deleted.
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
type ImageCleanupResult ¶ added in v0.2.0
func CleanupPlutoImageFiles ¶ added in v0.2.0
func CleanupPlutoImageFiles( imageId int, fileName string, ) (*ImageCleanupResult, error)
type ImageMetadata ¶
type Pluto ¶
var PlutoInstance *Pluto
func Initialize ¶ added in v0.1.3
New creates and initializes a new Pluto instance
func (*Pluto) RegisterRoutes ¶
func (pluto *Pluto) RegisterRoutes(rg *gin.RouterGroup, middlewares ...gin.HandlerFunc)