php特殊字体生成,生成艺术字体图片水印代码_PHP教程

public final class imageutils {

public imageutils() {

}

public final static string getpressimgpath(){

return applicationcontext.getrealpath("/template/data/util/shuiyin.gif");

}

/**

* 把图片印刷到图片上

* @param pressimg -- 水印文件

* @param targetimg -- 目标文件

* @param x

* @param y

*/

public final static void pressimage(string pressimg, string targetimg, int x, int y) {

try {

file _file = new file(targetimg);

image src = imageio.read(_file);

int wideth = src.getwidth(null);

int height = src.getheight(null);

bufferedimage image = new bufferedimage(wideth, height,

bufferedimage.type_int_rgb);

graphics g = image.creategraphics();

g.drawimage(src, 0, 0, wideth, height, null);

// 水印文件

file _filebiao = new file(pressimg);

image src_biao = imageio.read(_filebiao);

int wideth_biao = src_biao.getwidth(null);

int height_biao = src_biao.getheight(null);

g.drawimage(src_biao, wideth - wideth_biao - x, height - height_biao -y, wideth_biao,

height_biao, null);

// /

g.dispose();

fileoutputstream out = new fileoutputstream(targetimg);

jpegimageencoder encoder = jpegcodec.createjpegencoder(out);

encoder.encode(image);

out.close();

} catch (exception e) {

e.printstacktrace();

}

}

/**

* 打印文字水印图片

* @param presstext --文字

* @param targetimg -- 目标图片

* @param fontname -- 字体名

* @param fontstyle -- 字体样式

* @param color -- 字体颜色

* @param fontsize -- 字体大小

* @param x -- 偏移量

* @param y

*/

public static void presstext(string presstext, string targetimg, string fontname,int fontstyle, int color, int fontsize, int x, int y) {

try {

file _file = new file(targetimg);

image src = imageio.read(_file);

int wideth = src.getwidth(null);

int height = src.getheight(null);

bufferedimage image = new bufferedimage(wideth, height,

bufferedimage.type_int_rgb);

graphics g = image.creategraphics();

g.drawimage(src, 0, 0, wideth, height, null);

// string s=www.bKjia.c0m;

g.setcolor(color.red);

g.setfont(new font(fontname, fontstyle, fontsize));

g.drawstring(presstext, wideth - fontsize - x, height - fontsize/2 - y);

g.dispose();

fileoutputstream out = new fileoutputstream(targetimg);

jpegimageencoder encoder = jpegcodec.createjpegencoder(out);

encoder.encode(image);

out.close();

} catch (exception e) {

system.out.println(e);

}

}

public static void main(string[] args) {

pressimage("c:/shuiyin/shuiyin.gif", "c:/shuiyin/dsc02342.jpg", 20 ,20);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值