This plugin provides a way to watermark resources. It allows you to modify a base resource to add a link to your site, a logo, etc.
The initial goal of this plugin was to be able to watermark images when they are hotlinked from a foreign website, but may also provide utilities to watermark other kinds of content in the future.
You can use this plugin for many reasons, but one of them is to watermark resources
protected using the hotlinking protection
provided by Spincast. You redirect hotlinked images to a specific
route handler that uses
this plugin to generate watermarked versions of the base images.
The watermark this plugin creates can be based on some specified text or on an image you provide (a logo, for example).
@Inject protected SpincastWatermarkerFactory spincastWatermarkerFactory; SpincastImageWatermarker imgWatermarker = spincastWatermarkerFactory.imageWatermarkerBuilder() .text("My company name") .position(SpincastWatermarkPosition.BOTTOM_RIGHT) .build();
This watermarker would then be used to watermark images with a "
My company name"
text, at their bottom right.
Once you have created a
SpincastImageWatermarker instance, you can
watermark images using it:
imgWatermarker.watermark("/cat.jpg", true, new File(tempDirectory + "/cat-watermarked.jpg"));
In this example, a new "cat-watermarked.jpg" image would be created
and would contain a "
My company name" text watermark.
By default, if you don't specify any options, the resulting watermarker will add
text watermarks, at the bottom right of the base images, using the default
system font and the color black. This text will be the base URL of your
https://www.example.com" for example.) The background
will be white and a small black border will be added around the text.
Here are the options available when building a
Watermarker using the
When calling one of the "text(...)" overloads, you create a watermarker that will add some text to the base images. This method allows you to specify:
colorto use for the text.
fontto use when writing the text.
SpincastImageWatermarkerBuilder backgroundColor(Color color)
The color to use as the background for the watermark section. This option is only used when a text watermark is created, not when an image is used.
When calling one of the "image(...)" overloads, you create a watermarker
that will be based on an image you provide (your logo, for example).
This method requires the
path to the image to use
and allows you to specify if this image is on the classpath or on the
SpincastImageWatermarkerBuilder position(SpincastWatermarkPosition position, int margin)
position of the watermark. It can be:
This option also allows you to specify a
margin between the
watermark and the edge of the base images.
width of the watermark, relative to the width of the base image. It can
50 (50% width of the base image).
SpincastImageWatermarkerBuilder border(int widthInPixels, Color color)
Allows you to add a
border around the watermark. You can specify
the width of the border (in pixels) and its color. Use
0 as the width for no border at all!
Defaults to a 5 pixels black border.
Allows you to control the opacity of the watermark. It can go from "
(totally transparent) to "
1.0F" (totally opaque).
1. Add this Maven artifact to your project:
<dependency> <groupId>org.spincast</groupId> <artifactId>spincast-plugins-watermarker</artifactId> <version>2.0.1</version> </dependency>
Spincast.configure() .plugin(new SpincastWatermarkerPlugin()) // ...