【小白笔记】PHP学习之路 (30) --绘制文字及相关库函数

来源:互联网 发布:mysql 5.7.15安装图解 编辑:程序博客网 时间:2024/04/29 23:29

get_loaded_extensions()      获得已加载的扩展,返回数组。

get_extension_funcs()      指定库名,获得库中的函数列表。

extension_loaded()      指定库名,检测其是否已经加载,未加载返回false。


绘制文字相关函数:

imagechar()      水平地绘制一个字符。由于字体的问题,默认只能绘制英文。如果传参字符串,只绘制第一个字符。参数见手册。

imagecharup()      垂直地绘制一个字符。用法同上。

imagestring()      水平地绘制一个字符串。

imagestringup()      垂直地绘制一个字符串。

imagefontwidth()      获取指定大小字体的单个字符宽度。

imagefontheight()      获取指定大小字体的单个字符高度。

imagettftext()      绘制指定字体样式的文字。可以旋转角度。

imagettfbbox()                 计算包围着 TrueType 文本范围的虚拟方框的像素大小。

                                         返回包含文本四个角坐标的数组。可以利用两组对角坐标计算字串的宽度和高度。

                                         顺序依次为:0~1左下    2~3右下   4~5右上    6~7左上

iconv()      转换字符编码。

abs()      取绝对值。

以下仅为个人练习、作用法格式参考,详细请查询php手册:


function waterMark($r_img,$d_img='',$pos=1,$pct=80,$str='ABCDEFGHIJKL',$f_size=5,$color='#564325'){if(extension_loaded('gd') && file_exists($r_img) && getimagesize($r_img)){$str_len = strlen($str);$w = imagefontwidth($f_size) * $str_len;$h = imagefontwidth($f_size);$i_info = getimagesize($r_img);if($i_info[0]<$w || $i_info[1]<$h){return true;}switch($i_info[2]){case 1:$img = imagecreatefromgif($r_img);break;case 2:$img = imagecreatefromjpeg($r_img);break;case 3:$img = imagecreatefrompng($r_img);break;default:return false;}if(strlen($color)!=7) return false;$f_color = imagecolorallocate($img, hexdec(substr($color,1,2)), hexdec(substr($color,3,2)), hexdec(substr($color,5,2)));switch($pos){case 1:$x = $y = 8;break;case 2:$x = ($i_info[0]-$w)/2; //$y = 8;break;case 3:$x = $i_info[0]-$w;$y = 8;break;case 4:$x = 8;$y = $i_info[1]/2;break;case 5:$x = ($i_info[0]-$w)/2; $y = $i_info[1]/2;break;default:$x = mt_rand(8,$i_info[0]-$w);$y = mt_rand(8,$i_info[1]-$h);}imagestring($img, $f_size, $x, $y, $str, $f_color);$d_img = $d_img!='' ? $d_img : $r_img;switch ($i_info[2]){case 1:imagegif($img,$d_img);break;case 2:imagejpeg($img,$d_img,$pct);break;case 3:imagepng($img,$d_img);break;}imagedestroy($img);return true;}return false;} if(waterMark('pic5.jpg','ppp.jpg',6)){echo "加水印了<br/>";}else{echo "没加水印<br/>";}



0 0
原创粉丝点击