diff --git a/options.go b/options.go index 77f3ea80..8351b5d2 100644 --- a/options.go +++ b/options.go @@ -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 diff --git a/resizer.go b/resizer.go index d3bed897..80597d22 100644 --- a/resizer.go +++ b/resizer.go @@ -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 { diff --git a/vips.go b/vips.go index 6a775700..69b69319 100644 --- a/vips.go +++ b/vips.go @@ -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 @@ -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)) @@ -733,4 +734,4 @@ func vipsGamma(image *C.VipsImage, Gamma float64) (*C.VipsImage, error) { return nil, catchVipsError() } return out, nil -} \ No newline at end of file +} diff --git a/vips.h b/vips.h index 46ed2cae..66af9c9b 100644 --- a/vips.h +++ b/vips.h @@ -44,6 +44,8 @@ typedef struct { } WatermarkTextOptions; typedef struct { + int Left; + int Top; int Width; int DPI; int Margin; @@ -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;