足球游戏_中国足彩网¥体育资讯$

php 文字水印
来源:易贤网 阅读:1471 次 日期:2014-09-10 09:20:56
温馨提示:易贤网小编为您整理了“php 文字水印”,方便广大网友查阅!

php生成文字水印,并将图片另存,下面是代码,修改了多次,可以防止中文乱码,但是要求字体,根据下面的提示进行配置,这样php文字水印很容易就输出了。

//参数分别是 原始图片 保存图片 位置 文字水印内容 水印数量 文字水印颜色 文字水印字体

//字体在当前文件夹下

function imageWaterMark($groundImage,$savename,$pos=0,$waterText="",$number=1,$textColor="#cccccc",$font = "simhei.ttf")

{

$formatMsg = "仅仅能为GIF、JPG、PNG添加水印图片";

if($savename=="")$savename = $groundImage;

$font = dirname(__FILE__)."\\".$font;

$font = str_replace("\\","/",$font);

if(!empty($font) && !file_exists($font)){

die("font not exists");

}

if(!empty($groundImage) && file_exists($groundImage))

{

$ground_info = getimagesize($groundImage);

$ground_w = $ground_info[0];//取得背景图片的宽

$ground_h = $ground_info[1];//取得背景图片的高

switch($ground_info[2])//取得背景图片的格式

{

case 1:$ground_im = imagecreatefromgif($groundImage);break;

case 2:$ground_im = imagecreatefromjpeg($groundImage);break;

case 3:$ground_im = imagecreatefrompng($groundImage);break;

default:die($formatMsg);

}

}else{

die("需要加文字水印的图片不存在!");

}

$w = $h = 0 ;//这里是文字水印的的宽度和高度,无法定义

for($number;$number>1;$number--){

switch($pos)

{

case 0://随机

$posX = rand(50,($ground_w - $w ));

$posY = rand(120,($ground_h - $h ));

break;

case 1://文字水印顶端居左

$posX = 0;

$posY = 0;

break;

case 2://文字水印顶端居中

$posX = ($ground_w - $w) / 2;

$posY = 0;

break;

case 3://文字水印顶端居右

$posX = $ground_w - $w;

$posY = 0;

break;

case 4://文字水印中部居左

$posX = 0;

$posY = ($ground_h - $h) / 2;

break;

case 5://文字水印中部居中

$posX = ($ground_w - $w) / 2;

$posY = ($ground_h - $h) / 2;

break;

case 6://文字水印中部居右

$posX = $ground_w - $w;

$posY = ($ground_h - $h) / 2;

break;

case 7://文字水印底端居左

$posX = 0;

$posY = $ground_h - $h;

break;

case 8://文字水印底端居中

$posX = ($ground_w - $w) / 2;

$posY = $ground_h - $h;

break;

case 9://文字水印为底端居右

$posX = $ground_w - $w;

$posY = $ground_h - $h;

break;

case 11:

$posX = $ground_w - $w;

$posY = $ground_h - $h;

break;

default://文字水印随机

$posX = rand(0,($ground_w - $w));

$posY = rand(0,($ground_h - $h));

break;

}

//设定文字水印图片颜色图像的混色模式

imagealphablending($ground_im, true);

if( !empty($textColor) && (strlen($textColor)==7) ){

$R = hexdec(substr($textColor,1,2));

$G = hexdec(substr($textColor,3,2));

$B = hexdec(substr($textColor,5));

}else{

die("水印文字颜色格式不正确!");

}

imagettftext($ground_im, 20, 0, $posX, $posY, imagecolorallocate($ground_im, $R, $G, $B), $font, $waterText);//将文字写到图片中 img size angle beginx beginy color fonttype content

}

//@unlink($groundImage);

switch($ground_info[2])//取得背景图片的格式 ,并保存文字水印图片

{

case 1:imagegif($ground_im,$savename);break;

case 2:imagejpeg($ground_im,$savename);break;

case 3:imagepng($ground_im,$savename);break;

default:die($errorMsg);

}

//释放内存

unset($ground_info);

imagedestroy($ground_im);

}

上面就是php 生成文字水印图片函数,如果使用拿去吧。

中国足彩网信息请查看IT技术专栏

中国足彩网信息请查看网络编程
上一篇:tcpdf 中文乱码
易贤网手机网站地址:php 文字水印
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标