Java code to add watermark to the picture

Depend on the Hutooltool library, just POMimport it. Official website

<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.3.4</version>
</dependency>

Watermark code

ImgUtil.pressText(//
                FileUtil.file("c:/work/blog/git.jpg"), //
                FileUtil.file("c:/work/blog/git_1.jpg"), //
                "LitongZero", Color.BLACK, //文字
                new Font("黑体", Font.BOLD, 200), //字体
                100, //x坐标修正值。 默认在中间,偏移量相对于中间偏移
                400, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
                0.2f//透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字
        );

Support local files, or image streams

You can check the official website or source code for details. as follows
Insert picture description here

Guess you like

Origin blog.csdn.net/LitongZero/article/details/106478935