首页 > php教程 > php手册 > 正文

生成艺术字体图片水印代码

php中文网
发布: 2016-06-13 09:48:31
原创
2795人浏览过

//adv0.jpg就是背景图片,注意函数与图片格式对应   $im = imagecreatefromjpeg('/www/law/images/demo/adv0.jpg');    $font_color = imagecolorallocate ($im, 0, 250, 10); //这是文字颜色,绿色     $text = "张三的博客";                               //文字内容     $font_file = "/www/font/hyi_xkj.ttf";               //字体的linux绝对路径     //26:字体, 0 是角度, 10,36是坐标, $font_color是文字色, font是字体,  文本是填入的文字   imagettftext($im, 26,0, 10, 36, $font_color ,$font_file, $text);  往图片插入文字     // output image   header ('content-type: image/png');                 //即便是从jpg拷贝的图片,也能以png输出,   imagepng ($im);   // clean up   imagedestroy($im);


生成水印方法二

public final class imageutils {
public imageutils() {

}

 v7.0.0603UsualToolCMS大众版
v7.0.0603UsualToolCMS大众版

UsualToolCMS 是一款企业级的网站内容管理系统,由PHP+MYSQL编写,使用模板分离技术,支持创建多种类型的站点。 拥有UsualToolCMS便能快速同时在手机端与电脑端建立网站,通过UsualToolCMS能快速接入公众号,快速生成一个微信小程序及WEBAPP,真正的多站合一。互联网技术变得更简单。 升级说明: UsualToolCMS7.0.0604增加文字/图片自动水印系

 v7.0.0603UsualToolCMS大众版 77
查看详情  v7.0.0603UsualToolCMS大众版

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);
}
}

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号