com.gif4j
Class Watermark

java.lang.Object
  extended bycom.gif4j.Watermark

public class Watermark
extends java.lang.Object

This java class is used to prepare and apply (render with the specified transparency) images as watermarks. Absolute and layout positioning are supported.

The next examples demonstrate how this java class can be used separately to create and add watermarks to images (BufferedImage(-s)) and the whole gif images (GifImage(-s)). Please peruse the API, tutorial and external examples for additional features.

Add text watermark to BufferedImage using Java

 import com.gif4j.TextPainter;
 import com.gif4j.Watermark;
 import java.awt.*;
 import java.awt.image.BufferedImage;
 // ...
   public BufferedImage addTextWatermarkToImage(BufferedImage image, String watermarkText) {
       //create new TextPainter
       TextPainter textPainter = new TextPainter(new Font("Verdana", Font.BOLD, 10));
       textPainter.setOutlinePaint(Color.WHITE);
       //render the specified text outlined
       BufferedImage renderedWatermarkText = textPainter.renderString(watermarkText,true);
       //create new Watermark
       Watermark watermark = new Watermark(renderedWatermarkText, Watermark.LAYOUT_BOTTOM_RIGHT);
       //apply watermark to the specified image and return the result
       return watermark.apply(image);
   }
 

Add text watermark to GifImage using Java

 import com.gif4j.TextPainter;
 import com.gif4j.Watermark;
 import java.awt.*;
 import com.gif4j.GifImage;
 // ...
    public GifImage addTextWatermarkToGifImage(GifImage gifImage, String watermarkText) {
        //create new TextPainter
        TextPainter textPainter = new TextPainter(new Font("Verdana", Font.BOLD, 10));
        textPainter.setOutlinePaint(Color.WHITE);
        //render the specified text outlined
        BufferedImage renderedWatermarkText = textPainter.renderString(watermarkText, true);
        //create new Watermark
        Watermark watermark = new Watermark(renderedWatermarkText, Watermark.LAYOUT_BOTTOM_RIGHT);
        //apply watermark to the specified gif image and return the result
        return watermark.apply(gifImage, true);
    }
 

Version:
2.1
Author:
Gif4J Software - Java GIF image processing solutions
See Also:
GifImage, BufferedImage

Field Summary
static int LAYOUT_BOTTOM_CENTER
          The bottom-center layout constraint.
static int LAYOUT_BOTTOM_LEFT
          The bottom-left layout constraint.
static int LAYOUT_BOTTOM_RIGHT
          The bottom-right layout constraint.
static int LAYOUT_COVER_CONSECUTIVELY
          By providing this layout constraint an image will be covered by the watermark consecutively.
static int LAYOUT_MIDDLE_CENTER
          The middle-center layout constraint.
static int LAYOUT_MIDDLE_LEFT
          The middle-left layout constraint.
static int LAYOUT_MIDDLE_RIGHT
          The middle-right layout constraint.
static int LAYOUT_TOP_CENTER
          The top-center layout constraint
static int LAYOUT_TOP_LEFT
          The top-left layout constraint.
static int LAYOUT_TOP_RIGHT
          The top-right layout constraint.
 
Constructor Summary
Watermark(java.awt.image.BufferedImage watermarkImage, int layoutConstraint)
          Constructs Watermark from the specified BufferedImage with the specified layout position (final position is calculated according to the specified layout constraint before the applying process to the exact GifFrame starts), and 0.5 transparency (half-TRANSPARENT_COLOR).
Watermark(java.awt.image.BufferedImage watermarkImage, int layoutConstraint, float transparency)
          Constructs Watermark from the specified BufferedImage with the specified layout position (final position is calculated according to the specified layout constraint before the applying process to the exact GifFrame starts), and the specified transparency.
Watermark(java.awt.image.BufferedImage watermarkImage, java.awt.Point position)
          Constructs Watermark from the specified BufferedImage with the specified absolute position, and 0.5 transparency (half-TRANSPARENT_COLOR).
Watermark(java.awt.image.BufferedImage watermarkImage, java.awt.Point position, float transparency)
          Constructs Watermark from the specified BufferedImage with the specified absolute position and transparency parameter.
 
Method Summary
 java.awt.image.BufferedImage apply(java.awt.image.BufferedImage image)
          Apply the watermark to the specified image.
 GifImage apply(GifImage gifImage, boolean smooth)
          Apply the watermark to the specified GifImage.
 GifImage applyFrame(GifImage gifImage, int frameNumber, boolean smooth)
          Apply the watermark to the specified GifFrame within the specified GifImage.
 GifImage applyFull(GifImage gifImage, boolean smooth)
          Apply the watermark to the specified GifImage in full mode.
 void setLayoutConstraint(int layoutConstraint)
          Set the relative position where this instance should paint itself (final position is calculated according to the specified layout constraint before the applying process to the exact GifFrame starts)
 void setPosition(java.awt.Point position)
          set absolute position where this instance should paint itself
 void setTransparency(float transparency)
          Set watermark transparency
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LAYOUT_BOTTOM_CENTER

public static final int LAYOUT_BOTTOM_CENTER
The bottom-center layout constraint.

See Also:
Constant Field Values

LAYOUT_BOTTOM_LEFT

public static final int LAYOUT_BOTTOM_LEFT
The bottom-left layout constraint.

See Also:
Constant Field Values

LAYOUT_BOTTOM_RIGHT

public static final int LAYOUT_BOTTOM_RIGHT
The bottom-right layout constraint.

See Also:
Constant Field Values

LAYOUT_COVER_CONSECUTIVELY

public static final int LAYOUT_COVER_CONSECUTIVELY
By providing this layout constraint an image will be covered by the watermark consecutively.

See Also:
Constant Field Values

LAYOUT_MIDDLE_CENTER

public static final int LAYOUT_MIDDLE_CENTER
The middle-center layout constraint.

See Also:
Constant Field Values

LAYOUT_MIDDLE_LEFT

public static final int LAYOUT_MIDDLE_LEFT
The middle-left layout constraint.

See Also:
Constant Field Values

LAYOUT_MIDDLE_RIGHT

public static final int LAYOUT_MIDDLE_RIGHT
The middle-right layout constraint.

See Also:
Constant Field Values

LAYOUT_TOP_CENTER

public static final int LAYOUT_TOP_CENTER
The top-center layout constraint

See Also:
Constant Field Values

LAYOUT_TOP_LEFT

public static final int LAYOUT_TOP_LEFT
The top-left layout constraint.

See Also:
Constant Field Values

LAYOUT_TOP_RIGHT

public static final int LAYOUT_TOP_RIGHT
The top-right layout constraint.

See Also:
Constant Field Values
Constructor Detail

Watermark

public Watermark(java.awt.image.BufferedImage watermarkImage,
                 int layoutConstraint)
Constructs Watermark from the specified BufferedImage with the specified layout position (final position is calculated according to the specified layout constraint before the applying process to the exact GifFrame starts), and 0.5 transparency (half-TRANSPARENT_COLOR).

Parameters:
watermarkImage - the specified watermark image
layoutConstraint - one of the next: LAYOUT_TOP_LEFT, LAYOUT_TOP_CENTER, LAYOUT_TOP_RIGHT, LAYOUT_MIDDLE_LEFT, LAYOUT_MIDDLE_CENTER, LAYOUT_MIDDLE_RIGHT, LAYOUT_BOTTOM_LEFT, LAYOUT_BOTTOM_CENTER, LAYOUT_BOTTOM_RIGHT
Throws:
java.lang.NullPointerException - watermarkImage is null
java.lang.IllegalArgumentException - unknown layout constraint

Watermark

public Watermark(java.awt.image.BufferedImage watermarkImage,
                 int layoutConstraint,
                 float transparency)
Constructs Watermark from the specified BufferedImage with the specified layout position (final position is calculated according to the specified layout constraint before the applying process to the exact GifFrame starts), and the specified transparency.

Parameters:
watermarkImage - the specified watermark image
layoutConstraint - one of the next: LAYOUT_TOP_LEFT, LAYOUT_TOP_CENTER, LAYOUT_TOP_RIGHT, LAYOUT_MIDDLE_LEFT, LAYOUT_MIDDLE_CENTER, LAYOUT_MIDDLE_RIGHT, LAYOUT_BOTTOM_LEFT, LAYOUT_BOTTOM_CENTER, LAYOUT_BOTTOM_RIGHT
transparency - transparency parameter, must be between 0 (absolutely TRANSPARENT_COLOR) and 1 (absolutely opaque).
Throws:
java.lang.NullPointerException - watermarkImage is null
java.lang.IllegalArgumentException - unknown layout constraint

Watermark

public Watermark(java.awt.image.BufferedImage watermarkImage,
                 java.awt.Point position)
Constructs Watermark from the specified BufferedImage with the specified absolute position, and 0.5 transparency (half-TRANSPARENT_COLOR).

Parameters:
watermarkImage - the specified watermark image
position - absolute position where this watermark should be painted at
Throws:
java.lang.NullPointerException - watermarkImage is null

Watermark

public Watermark(java.awt.image.BufferedImage watermarkImage,
                 java.awt.Point position,
                 float transparency)
Constructs Watermark from the specified BufferedImage with the specified absolute position and transparency parameter.

Parameters:
watermarkImage - the specified watermark image
position - absolute position where this watermark should be painted at
transparency - the specified transparency, must be between 0 (absolutely TRANSPARENT_COLOR) and 1 (absolutely opaque).
Throws:
java.lang.NullPointerException - watermarkImage is null
Method Detail

apply

public java.awt.image.BufferedImage apply(java.awt.image.BufferedImage image)
Apply the watermark to the specified image. The watermark image is rendered with the specified transparency at the specified absolute or relative position.

Parameters:
image - BufferedImage to apply watermark to
Returns:
new BufferedImage instance with rendered watermark

apply

public GifImage apply(GifImage gifImage,
                      boolean smooth)
Apply the watermark to the specified GifImage. The image watermark is rendered with the specified transparency at the specified position. The watermark image is applied to the whole GifImage.

Parameters:
gifImage - GifImage to apply watermark to
smooth - choose a watermark-rendering algorithm. If true then the watermark-rendering algorithm that gives higher priority to GifImage smoothness than rendering speed is used.
Returns:
new GifImage instance with rendered watermark
Since:
2.0

applyFrame

public final GifImage applyFrame(GifImage gifImage,
                                 int frameNumber,
                                 boolean smooth)
Apply the watermark to the specified GifFrame within the specified GifImage. The image watermark is rendered with the specified transparency at the specified position.

Parameters:
gifImage - GifImage to apply watermark to
frameNumber - number of frame to apply watermark to
smooth - choose a watermark-rendering algorithm. If true then the watermark-rendering algorithm that gives higher priority to GifImage smoothness than rendering speed is used.
Returns:
new GifImage instance with rendered watermark
Since:
2.1

applyFull

public final GifImage applyFull(GifImage gifImage,
                                boolean smooth)
Apply the watermark to the specified GifImage in full mode. The image watermark is rendered with the specified transparency at the specified position. The watermark image is applied to the whole GifImage.

Parameters:
gifImage - GifImage to apply watermark to
smooth - choose a watermark-rendering algorithm. If true then the watermark-rendering algorithm that gives higher priority to GifImage smoothness than rendering speed is used.
Returns:
new GifImage instance with rendered watermark
Since:
2.0

setLayoutConstraint

public void setLayoutConstraint(int layoutConstraint)
Set the relative position where this instance should paint itself (final position is calculated according to the specified layout constraint before the applying process to the exact GifFrame starts)

Parameters:
layoutConstraint - one of the next: LAYOUT_TOP_LEFT, LAYOUT_TOP_CENTER, LAYOUT_TOP_RIGHT, LAYOUT_MIDDLE_LEFT, LAYOUT_MIDDLE_CENTER, LAYOUT_MIDDLE_RIGHT, LAYOUT_BOTTOM_LEFT, LAYOUT_BOTTOM_CENTER, LAYOUT_BOTTOM_RIGHT
Throws:
java.lang.IllegalArgumentException - unknown layout constraint

setPosition

public void setPosition(java.awt.Point position)
set absolute position where this instance should paint itself

Parameters:
position - point instance with positive coordinates

setTransparency

public void setTransparency(float transparency)
Set watermark transparency

Parameters:
transparency - transparency parameter, must be between 0 (absolutely TRANSPARENT_COLOR) and 1 (absolutely opaque).