watermark

package module
v0.0.0-...-2eeed56 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 15 Imported by: 0

README

Watermark

Add text mark to image.

Install

go get github.com/fzdwx/watermark

Usage

package main

import (
	"github.com/fzdwx/watermark"
	"os"
	"testing"
)

func TestText(t *testing.T) {
	c := watermark.NewClient()

	f, err := os.Open("demo.jpg")
	if err != nil {
		t.Fatal(err)
	}
	defer f.Close()

	option := watermark.DefaultTextMarkOption()
	mask, err := c.AddTextMask("Hello", f, watermark.ImageFormatJpg, option)
	if err != nil {
		t.Fatal(err)
	}

	f, err = os.Create("demo_watermark.jpg")
	if err != nil {
		t.Fatal(err)
	}
	defer f.Close()
	_, err = f.Write(mask)
}

Before

before

After

after

License

MIT and Inspired by weixin_40660221.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {

	// AddTextMark add text mark
	// text water text
	// source image source
	// format image format
	// option see DefaultTextMarkOption
	AddTextMark(text string, source io.Reader, format ImageFormat, option *TextMarkOption) ([]byte, error)
}

func NewClient

func NewClient() Client

NewClient new watermark client

type ImageFormat

type ImageFormat string
const (
	ImageFormatPng  ImageFormat = "png"
	ImageFormatJpeg ImageFormat = "jpeg"
	ImageFormatJpg  ImageFormat = "jpg"
	ImageFormatGif  ImageFormat = "gif"
	ImageFormatWebp ImageFormat = "webp"
)

type Option

type Option struct {
	// Output image quality
	// for jpg/jpeg/webp
	// 0~100
	Quality float64
	// Watermark Image gap
	StepX, StepY int
	// Watermark Image rotate angle
	Skew float64
}

type TextMarkOption

type TextMarkOption struct {
	*Option
	// Text font
	Font *truetype.Font
	// Font size
	FontSize float64
	// Text color
	TextColor color.Color
	Dpi       float64
}

func DefaultTextMarkOption

func DefaultTextMarkOption() *TextMarkOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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