php在图片上增加矩形框并加入水印

WBOY
Release: 2016-06-13 11:01:06
Original
901 people have browsed it

php在图片下增加矩形框并加入水印

 //统计混合汉字英文字符的实际字符数,只对gb2312码有效 function str_len($str){ $length=0; for($i=0;$i<strlen if>0x80) $i++; $length++; } return $length; } //待添加水印图片 $imagefile = "3.jpg"; //待添加文字 $str = "照片由戈多上传于".date("Y年m月d日H时i分s秒"); //由于掺杂汉字,原生函数无法统计真实字符数,造成水印文字无法居中 //所以自己写了个函数统计,如果有mbstring库支持,换用mb_strlen也可以 $len = str_len($str); //如果源程序基于utf-8编码,不需要做字符转换,删除此行 $str = iconv('gb2312','utf-8',$str); //获取原图大小 $size = getimagesize($imagefile); //底边矩形高度 $bottom_height = 20; //字体大小 $font_size = 10; $im = imagecreatetruecolor($size[0], $size[1]+$bottom_height); //底边矩形背景色,修改最后三个RGB参数改变颜色 $bgcolor = imagecolorallocate($im,100,120,100); //字体颜色 $ftcolor = imagecolorallocate($im,255,255,255); imagefill($im,0,0,$bgcolor); //默认从jpeg创建,如从其他图片创建,可根据扩展名选择函数 $jpeg = imagecreatefromjpeg($imagefile); imagecopy($im,$jpeg,0,0,0,0,$size[0],$size[1]); $start_x = ($size[0]-$len*$font_size)/2; $start_x = ($start_x>0?$start_x:0); $start_y = $size[1]+$font_size+($bottom_height-$font_size)/2; //C:/windows/fonts/SIMHEI.TTF为ttf字库文件,此处为黑体 imagettftext($im,$font_size,0,$start_x,$start_y,$ftcolor,"C:/windows/fonts/SIMHEI.TTF",$str); header("Content-type: image/jpeg"); imagejpeg($im); imageclose($im); imageclose($jpeg); ?> </strlen>
Copy after login

?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template