Skip to content

Instantly share code, notes, and snippets.

@lucacesari
Last active August 29, 2015 14:06
Show Gist options
  • Save lucacesari/ab265c68df0bdb23728b to your computer and use it in GitHub Desktop.
Save lucacesari/ab265c68df0bdb23728b to your computer and use it in GitHub Desktop.
(Buffered)Image watermarking
private static BufferedImage watermark(BufferedImage image, String text) {
final FontMetrics fm = graphics.getFontMetrics();
// center text string
final int x = (image.getWidth() / 2) - fm.stringWidth(text);
final int y = (image.getHeight() / 2) - fm.getHeight();
final Graphics2D graphics = image.createGraphics();
graphics.setPaint(Color.white);
graphics.setFont(new Font("SansSerif", Font.BOLD, 10));
graphics.drawString(text, x, y);
graphics.dispose();
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment