diff --git a/README.md b/README.md index 2351ece29..c6bcfc1e1 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ imagor supports the following filters: - `strip_icc()` removes ICC profile information from the resulting image - `strip_metadata()` removes all metadata from the resulting image - `upscale()` upscale the image if `fit-in` is used -- `watermark(image, x, y, alpha [, w_ratio [, h_ratio]])` adds a watermark to the image. It can be positioned inside the image with the alpha channel specified and optionally resized based on the image size by specifying the ratio +- `watermark(image, x, y, alpha [, w_ratio [, h_ratio [, resize_mode]]])` adds a watermark to the image. It can be positioned inside the image with the alpha channel specified and optionally resized based on the image size by specifying the ratio - `image` watermark image URI, using the same image loader configured for imagor - `x` horizontal position that the watermark will be in: - Positive number indicate position from the left, negative number from the right. @@ -149,6 +149,7 @@ imagor supports the following filters: - `alpha` watermark image transparency, a number between 0 (fully opaque) and 100 (fully transparent). - `w_ratio` percentage of the width of the image the watermark should fit-in - `h_ratio` percentage of the height of the image the watermark should fit-in + - `resize_mode` resize mode of the watermark. If 'force', the watermark will be resized to w_ratio and h_ratio regardless of the watermark's aspect ratio. Otherwise, the watermark will be resized to fit within the w_ratio and h_ratio, respecting its aspect ratio. #### Utility Filters diff --git a/vips/filter.go b/vips/filter.go index 6c3b98f73..ef41851bc 100644 --- a/vips/filter.go +++ b/vips/filter.go @@ -32,9 +32,14 @@ func (v *Processor) watermark(ctx context.Context, img *Image, load imagor.LoadF var down = 1 var overlay *Image var n = 1 + resizeMode := SizeBoth if isAnimated(img) { n = -1 } + // resize_mode + if ln >= 7 && args[6] == "force" { + resizeMode = SizeForce + } // w_ratio h_ratio if ln >= 6 { w = img.Width() @@ -47,8 +52,9 @@ func (v *Processor) watermark(ctx context.Context, img *Image, load imagor.LoadF h, _ = strconv.Atoi(args[5]) h = img.PageHeight() * h / 100 } + if overlay, err = v.NewThumbnail( - ctx, blob, w, h, InterestingNone, SizeBoth, n, 1, 0, + ctx, blob, w, h, InterestingNone, resizeMode, n, 1, 0, ); err != nil { return }