Home > Back-end >  How do I use Java implementation effect of text watermarking in this picture?
How do I use Java implementation effect of text watermarking in this picture?

Time:10-26




I now have a demand, is to give a picture, give a paragraph of text, then the effect of the generated like the above picture, the text is very clear, can word wrap, and words have a gray transparent background, and then you can set the text shows the location of the (top, vertical center, at the bottom), set the text size color, like how to achieve this effect, please?

CodePudding user response:

Image processing can use opencv, lz oneself Google baidu opencv package to try

CodePudding user response:

The following code to add watermark images, you can specify a location, text font (song typeface, bold, etc.), whether the text bold, text color, gray transparent background, as to what you say can be separate images superimposed on the text, I have here with the original text watermarking method for your reference, the effect is as follows:


The sample code:
 public final static void pressText (String pressText, 
String srcImageFile, String destImageFile, String fontName,
Int fontStyle, Color Color, int fontSize, int x,
{int y, float alpha)
Try {
The File img=new File (srcImageFile);
Image SRC=https://bbs.csdn.net/topics/ImageIO.read (img);
Int width=SRC. GetWidth (null);
Int height=SRC. GetHeight (null);
BufferedImage image=new BufferedImage (width, height,
BufferedImage. TYPE_INT_RGB);
Graphics2D g=image. CreateGraphics ();
G.d rawImage (SRC, 0, 0, width, height, null);
G.s etColor (color);
G.s etFont (new Font (fontName fontStyle, fontSize));
G.s etComposite (AlphaComposite. GetInstance (AlphaComposite. SRC_ATOP,
Alpha));
//at the specified coordinates to draw text watermarking
G.d rawString (pressText, (width - (getLength (pressText) * fontSize))
/2 + x, (height - fontSize)/2 + y);
G.d ispose ();
ImageIO. Write ((BufferedImage) image, "JPEG", the new File (destImageFile));//output to a file stream
} the catch (Exception e) {
e.printStackTrace();
}
}


Call example:
 pressText (" I am watermark text ", "D:/1920 JPG", "D:/1920 _presstext. JPG", "song typeface, Font, BOLD, Color. White, 80, 0, 0, 0.5 f); 

CodePudding user response:

I this requirement cannot be fixed position, because the original highly uncertain, the text is likely more, also need to wrap text,

CodePudding user response:

2 d image processing, multiple libraries can be used,
Text watermarking
1 words generated transparent background pictures, you can specify fonts, bold, etc., word wrap is to obtain image width, font width/word spacing after calculation,
Superposition of two images,


Reference:

https://www.jianshu.com/p/44e09d43082e
  • Related