How can I create a watermark over an image using Java? I need user-entered text to be added to a provided position over an image. Any sample code/suggestions will help.
相关问题
- Views base64 encoded blob in HTML with PHP
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- How to get the background from multiple images by
Below is the code to add water mark on any image
}
use this code, it works.. here, an image is used as a watermark and is place at location 10,10
First intall Imagemagick in C:\Imagemagick folder in windows using
http://www.imagemagick.org/download/binaries/ImageMagick-6.8.8-7-Q16-x86-dll.exe
while installation add C:\ImageMagick; in PATH enviornment variable
and use below code
}
You can have a look to the "Drawing the Watermark" section of http://web.archive.org/web/20080324030029/http://blog.codebeach.com/2008/02/watermarking-images-in-java-servlet.html
Or you may use the GIF4J library http://www.gif4j.com/java-gif4j-pro-gif-image-watermark.htm#gifimagewatermarkapply
In Thumbnailator, one can add a text caption to an existing image by using the
Caption
image filter:In the above code, the text
Hello World
will be drawn on centered on theoriginalImage
with a Monospaced font, with a black foreground color, at 14 pt.Alternatively, if a watermark image is to be applied to an existing image, one can use the
Watermark
image filter:The above code will superimpose the
watermarkImage
on top of theoriginalImage
, centered with an opacity of 50%.Thumbnailator will run on plain old Java SE -- one does not have to install any third party libraries. (However, using the Sun Java runtime is required.)
Full disclosure: I am the developer for Thumbnailator.
I had a similar need recently and found this post rather useful: http://www.codeyouneed.com/java-watermark-image/
The watermark method there uses ImgScalr for resizing the watermark when needed and supports placing text in the bottom / top of the image + the watermark image.
For choosing the correct placement it uses a simple ENUM
And the whole watermarking logic is in this method:
And the corresponding methods for calculating the watermark size is:
Again, all credits to http://www.codeyouneed.com/java-watermark-image/ for a nice sample.