Last active
August 29, 2015 14:06
-
-
Save lucacesari/ab265c68df0bdb23728b to your computer and use it in GitHub Desktop.
(Buffered)Image watermarking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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