Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ var ColorBlack = Color{0, 0, 0}

// Watermark represents the text-based watermark supported options.
type Watermark struct {
Left int
Top int
Width int
DPI int
Margin int
Expand Down
3 changes: 0 additions & 3 deletions resizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,6 @@ func watermarkImageWithText(image *C.VipsImage, w Watermark) (*C.VipsImage, erro
if w.DPI == 0 {
w.DPI = 150
}
if w.Margin == 0 {
w.Margin = w.Width
}
if w.Opacity == 0 {
w.Opacity = 0.25
} else if w.Opacity > 1 {
Expand Down
7 changes: 4 additions & 3 deletions vips.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type vipsSaveOptions struct {
}

type vipsWatermarkOptions struct {
Left C.int
Top C.int
Width C.int
DPI C.int
Margin C.int
Expand Down Expand Up @@ -285,8 +287,7 @@ func vipsWatermark(image *C.VipsImage, w Watermark) (*C.VipsImage, error) {
background := [3]C.double{C.double(w.Background.R), C.double(w.Background.G), C.double(w.Background.B)}

textOpts := vipsWatermarkTextOptions{text, font}
opts := vipsWatermarkOptions{C.int(w.Width), C.int(w.DPI), C.int(w.Margin), C.int(noReplicate), C.float(w.Opacity), background}

opts := vipsWatermarkOptions{C.int(w.Left), C.int(w.Top), C.int(w.Width), C.int(w.DPI), C.int(w.Margin), C.int(noReplicate), C.float(w.Opacity), background}
defer C.free(unsafe.Pointer(text))
defer C.free(unsafe.Pointer(font))

Expand Down Expand Up @@ -733,4 +734,4 @@ func vipsGamma(image *C.VipsImage, Gamma float64) (*C.VipsImage, error) {
return nil, catchVipsError()
}
return out, nil
}
}
4 changes: 3 additions & 1 deletion vips.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ typedef struct {
} WatermarkTextOptions;

typedef struct {
int Left;
int Top;
int Width;
int DPI;
int Margin;
Expand Down Expand Up @@ -442,7 +444,7 @@ vips_watermark(VipsImage *in, VipsImage **out, WatermarkTextOptions *to, Waterma
NULL) ||
vips_linear1(t[1], &t[2], o->Opacity, 0.0, NULL) ||
vips_cast(t[2], &t[3], VIPS_FORMAT_UCHAR, NULL) ||
vips_embed(t[3], &t[4], 100, 100, t[3]->Xsize + o->Margin, t[3]->Ysize + o->Margin, NULL)
vips_embed(t[3], &t[4], o->Left, o->Top, t[3]->Xsize + o->Margin + o->Left, t[3]->Ysize + o->Margin + o->Top, NULL)
) {
g_object_unref(base);
return 1;
Expand Down