watermark

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxWhatsAppDim is the maximum pixel dimension (longest side) for WhatsApp HD output.
	MaxWhatsAppDim = 2560
	// JPEGQuality is the JPEG encoding quality used for all output files.
	JPEGQuality = 92
)

Variables

This section is empty.

Functions

func AddWatermark

func AddWatermark(img image.Image, s PhotoSettings, opacity float64) (image.Image, error)

AddWatermark stamps a translucent pill-shaped overlay containing the camera settings from s onto img. opacity controls the background pill transparency (0 = invisible, 1 = fully opaque). When s contains no data the image is returned unchanged and no error is raised.

func ApplyOrientation

func ApplyOrientation(img image.Image, x *exiflib.Exif) image.Image

ApplyOrientation rotates img to its upright position according to the EXIF orientation tag. It is a no-op when x is nil or the orientation tag is absent or has value 1 (normal).

func CollectFiles

func CollectFiles(args []string) ([]string, error)

CollectFiles expands the given paths (files or directories) into a flat list of supported image files. Directories are walked recursively. Unsupported files are skipped with a message to stderr. An error is returned only when a path cannot be stat'd.

func DecodeImage

func DecodeImage(path string) (image.Image, error)

DecodeImage decodes a JPEG, PNG, or ARW file at path into an image.Image. ARW files are attempted via three fallback strategies: embedded JPEG extraction, dcraw, then ImageMagick. An error is returned only when all strategies fail or the file cannot be opened.

func IsSupportedExt

func IsSupportedExt(path string) bool

IsSupportedExt reports whether path has a supported image extension (arw, jpg, jpeg, or png, case-insensitive).

func OutputPath

func OutputPath(inputPath, outDir string) string

OutputPath returns the output file path for inputPath placed under outDir, replacing the original extension with .jpg.

func ProcessFile

func ProcessFile(inputPath, outDir string, opacity float64) error

ProcessFile is the single entry point for processing one image file. It reads EXIF metadata, decodes the image, applies orientation correction, resizes it to WhatsApp HD dimensions, stamps the watermark, and writes a JPEG to outDir.

func ResizeForWhatsApp

func ResizeForWhatsApp(img image.Image) image.Image

ResizeForWhatsApp downsizes img so its longest side is at most MaxWhatsAppDim pixels, preserving the aspect ratio using CatmullRom resampling. Images already within the limit are returned unchanged.

Types

type PhotoSettings

type PhotoSettings struct {
	Aperture     string
	ShutterSpeed string
	ISO          string
	FocalLength  string
	CameraModel  string
}

PhotoSettings holds the EXIF camera-settings fields extracted from a photo. Fields that are absent in the EXIF data are left as empty strings.

func ReadEXIF

func ReadEXIF(path string) (PhotoSettings, *exiflib.Exif)

ReadEXIF reads EXIF metadata from the file at path and returns the camera settings and the raw Exif value (used for orientation correction). On any read or decode failure an empty PhotoSettings and nil Exif are returned so the caller can still process the image without metadata.

Jump to

Keyboard shortcuts

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