imagewatermark

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 6 Imported by: 0

README

🧊 Go Image Watermarking Package

This Go package provides a simple and configurable way to overlay watermarks on images. It lets you control watermark opacity, size, alignment and rotation.


📄 Usage

import "github.com/filipenevs/go-imagewatermark"
Basic Example
result, err := imagewatermark.ProcessImageWithWatermark(imagewatermark.WatermarkConfig{
	InputPath:             "input.png",
	WatermarkPath:         "logo.png",
	OpacityAlpha:          0.6,
	WatermarkWidthPercent: 20,
	VerticalAlign:         imagewatermark.VerticalBottom,
	HorizontalAlign:       imagewatermark.HorizontalRight,
	Spacing:               20,
	RotationDegrees:       45,
})

if err != nil {
	log.Fatalf("Failed to add watermark: %v", err)
}

📚 API Reference

Types
WatermarkConfig
Field Type Description
InputPath string Path to the input image file
WatermarkPath string Path to the watermark image (supports transparency)
OpacityAlpha float64 Opacity level (e.g., 0.5 = 50% transparency)
WatermarkWidthPercent float64 Width of the watermark as % of image width
VerticalAlign VerticalAlign Vertical alignment: top, mid, bottom, rand
HorizontalAlign HorizontalAlign Horizontal alignment: left, mid, right, rand
Spacing int Padding in pixels from aligned edge
RotationDegrees float64 Rotation angle in degrees

📜 License

MIT License. See LICENSE file for details.


🤝 Contributing

Pull requests and issues are welcome!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessImageWithWatermark

func ProcessImageWithWatermark(
	config WatermarkConfig,
) (image.Image, error)

ProcessImageWithWatermark overlays a watermark onto an input image based on the provided configuration.

Parameters:

  • config: WatermarkConfig struct containing paths, opacity, size, alignment, and rotation settings.

Returns:

  • An image.Image containing the final image with the watermark applied.
  • An error if any step fails, such as invalid configuration or failure to load images.

Types

type HorizontalAlign

type HorizontalAlign string
const (
	HorizontalLeft   HorizontalAlign = "left"
	HorizontalMiddle HorizontalAlign = "mid"
	HorizontalRight  HorizontalAlign = "right"
	HorizontalRandom HorizontalAlign = "rand"
)

type VerticalAlign

type VerticalAlign string
const (
	VerticalTop    VerticalAlign = "top"
	VerticalMiddle VerticalAlign = "mid"
	VerticalBottom VerticalAlign = "bottom"
	VerticalRandom VerticalAlign = "rand"
)

type WatermarkConfig

type WatermarkConfig struct {
	InputPath             string
	WatermarkPath         string
	OpacityAlpha          float64
	WatermarkWidthPercent float64
	VerticalAlign         VerticalAlign
	HorizontalAlign       HorizontalAlign
	Spacing               int
	RotationDegrees       float64
}

WatermarkConfig holds configuration for watermarking a image. It includes input paths and watermark appearance options.

Jump to

Keyboard shortcuts

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