Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Text Watermark to Images using Java (JPG , PNG)
// Add Text Watermark to JPG using Java
TextWatermark watermark = new TextWatermark("GroupDocs", new Font("Arial", 30, FontStyle.Bold | FontStyle.Italic));
// Set Watermark properties
watermark.setForegroundColor(Color.getRed());
watermark.setTextAlignment(TextAlignment.Right);
watermark.setOpacity(0.4);
watermark.setX(70);
watermark.setY(130);
// Add Watermark to the source JPG Image
Watermarker watermarker = new Watermarker(Constants.JPG_GD);
watermarker.add(watermark);
watermarker.save(Constants.JPG_OUT);
watermarker.close();
// Add Text Watermark to PNG using Java
TextWatermark watermark = new TextWatermark("GroupDocs", new Font("Arial", 30, FontStyle.Bold | FontStyle.Italic));
// Set Watermark properties
watermark.setForegroundColor(Color.getBlack());
watermark.setTextAlignment(TextAlignment.Right);
watermark.setRotateAngle(-30);
watermark.setOpacity(0.4);
watermark.setX(70);
watermark.setY(70);
// Add Watermark to the source PNG Image
Watermarker watermarker = new Watermarker(Constants.PNG_GD);
watermarker.add(watermark);
watermarker.save(Constants.OUTPUT_PNG_PATH);
watermarker.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.