php 文字水印_
php生成文字水印,并将图片另存,下面是代码,修改了多次,可以防止中文乱码,但是要求字体,依据下面的提示进行配置,这样php文字水印很简单就输出了。
//参数分别是 原始图片 保存图片 位置 文字水印内容 水印数量 文字水印颜 文字水印字体
//字体在当前文件夹下
function imageWaterMark($groundImage,$savename,$pos=0,$waterText="",$number=1,$textColor="#cccccc",$font = "f")
{
$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");
//参数分别是 原始图片 保存图片 位置 文字水印内容 水印数量 文字水印颜 文字水印字体
//字体在当前文件夹下
function imageWaterMark($groundImage,$savename,$pos=0,$waterText="",$number=1,$textColor="#cccccc",$font = "f")
{
$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("需要加文字水印的图片不存在!");
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;$number1;$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;
$w = $h = 0 ;//这里是文字水印的的宽度和高度,无法定义
for($number;$number1;$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://文字水印中部居中 2014开学第一课
$posX = ($ground_w - $w) / 2;
$posY = ($ground_h - $h) / 2;
break;
case 6://文字水印中部居右
break;
case 3://文字水印顶端居右
$posX = $ground_w - $w;
$posY = 0;
break;
case 4://文字水印中部居左
$posX = 0;
$posY = ($ground_h - $h) / 2;
break;
case 5://文字水印中部居中 2014开学第一课
$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;
$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));
$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; 火炬之光2 联机
case 3:imagepng($ground_im,$savename);break;
default:die($errorMsg);
}
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; 火炬之光2 联机
case 3:imagepng($ground_im,$savename);break;
default:die($errorMsg);
}
//释放内存
unset($ground_info);
imagedestroy($ground_im);
}
上面就是php 生成文字水印图片函数,假如用法拿去吧。
更多信息请查看IT技术专栏
...
unset($ground_info);
imagedestroy($ground_im);
}
上面就是php 生成文字水印图片函数,假如用法拿去吧。
更多信息请查看IT技术专栏
...
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论