php实现了给图片添加笔画和马赛克的方法
阐述了用php在图片中添加笔画字和马赛克的方法。分享给大家参考。具体实现方法如下:
马赛克:空图像蒙版(资源图像,intx1,inty1,intx2,inty2,intdeep)
Imagemask()用坐标x1,y1到x2,y2(图像左上角为0,0)对矩形区域进行镶嵌。
深是模糊度,数字越大越模糊。
描边:void imagetextouter(资源图像、int大小、int x、int y、字符串颜色、字符串字体文件、字符串文本、字符串外部颜色)
Imagetextouter()在image表示的图像上绘制字符串文本,从坐标x,y开始(左上角为0,0),颜色为color,边框颜色为outercolor,使用fontfile指定的truetype fontfile。
如果没有指定字体文件,则使用gd的内部字体。根据php使用的不同gd库,如果fontfile不以'/','开头。“TTF”将被追加到文件名中,并且将搜索库来定义字体路径。
如果指定了字体文件,则由x和y表示的坐标定义第一个字符的基点(可能是字符的左下角)。否则,x和y定义第一个字符的右上角。
Fontfile是您要使用的truetype字体的文件名。
文本是一个文本字符串,它可以包含utf-8字符序列(格式:{)来访问字体中的前255个字符。
Color是十六进制格式的颜色#rrggbb,例如,#ff0000是红色。
外部颜色笔画颜色,十六进制#rrggbb格式。复制代码代码如下:PHP/* * * GD image mask * * @版权所有ugia.cn */函数imagemask($im,$x1,$y1,$x2,$y2,$ deep){ for($ x=$ x1;$ x $ x2$ x=$ deep){ for($ y=$ y1;$ y $ y2$ y=$ deep){ $ color=imagecolorat($ im,$x round($deep/2),$ y round($ deep/2));imagefiledrectangle($ im,$x,$y,$x $deep,$y $deep,$ color);} } }//马赛克用法示例:header(' content-type : image/png ');$ im=imagecreatefrom JPEG(' test . jpg ');imagemask($im,57,22,103,40,8);image png($ im);image destroy($ im);
运行效果如下图所示:
你好绿筠小姐3330吗?PHP/* * * GD图像文本外部* * @ ugia。cn */function imagetextuter($ im 、$size 、$x 、$y 、$color 、$fontfile 、$text 、$outer) { if(!function _ exists(' imagecoloracalatehex '){ function imagecoloracalatehex($ im,$ s){ if($ s { 0 }=' #)$ s=substr($ s,1);$ BG _ dec=十六进制dec($ s);return imagecolorable($ im,$bg_dec0xff0000) 16,($bg_dec0x00ff00) 8,($ BG _ dec0x 0000 ff));} $ TTF=false if(is _ file($ font file)){ $ TTF=true;$ area=imagettbbox($ size 、$angle 、$fontfile 、$ text );$ width=$ area[2]-$ area[0]2;$高度=$面积[1]-$面积[5]2;} else { $ width=strlen($ text)* 10;$ height=16 } $ im _ tmp=image create($ width、$ height);$ white=imagecolor allocate($ im _ tmp,255,255,255);$ black=imagecolor allocate($ im _ tmp,0,0,0);$ color=imagecolordallocatehex($ im、$ color);$ outer=imagecolorable hex($ im、$ outer);if($ TTF){ imagetttext($ im _ tmp、$size、0.0、$height - 2、$black、$fontfile、$ text);imagetttext($ im 、$size 、$ 0 、$x 、$y 、$color 、$fontfile 、$ text );$ y=$ y-$身高2;} else { imagestring($im_tmp、$size、0.0、$text、$ black);imagestring($im 、$size 、$x 、$y 、$text 、$ color );} for($ I=0);$ width $ I){ for($ j=0);$ j $ height $ j){ $ c=imagecolorat($ im _ tmp、$i、$ j);if ($c!==$white) { imagecolorat ($im_tmp、$i、$j - 1)!=$white || imagesetpixel($im、$x $i、$y $j - 1、$ outer);imagecolorat ($im_tmp、$i、$j 1)!=$white || imagesetpixel($im、$x $i、$j 1、$ outer);imagecolorat ($im_tmp、$i - 1、$j)!=$white || imagesetpixel($im、$x $i - 1、$y $j、$ outer);imagecolorat ($im_tmp、$i、$j)!=$white || imagesetpixel($im、$x $i 1、$y $j、$ outer);//你好,-什么烟花,烟火中的-你好-你好/* imagecolorat ($im_tmp、$i - 1、$j - 1)!=$white || imagesetpixel($im、$x $i - 1、$y $j - 1、$ outer);imagecolorat ($im_tmp、$i 1、$j - 1)!=$white || imagesetpixel($im、$x $i 1、$y $j - 1、$ outer);imagecolorat ($im_tmp、$i - 1、$j 1)!=$white || imagesetpixel($im、$x $i - 1、$j 1、$ outer);imagecolorat ($im_tmp 、$i 1 、$j 1)!=$white || imagesetpixel($im、$x $i 1、$j 1、$ outer);*/} } image designer($ im _ tmp);}
//云娥:标头(“内容类型:图像/png”);$ im=imagecreatefromjpeg('蓝天。jpg’);$white=imagecolorallocate($im,255,255,255);imagetextuter($ im,9,10,20,' #000000 ',' simsun。ttc ','-你好-你好ff ffimagetextuter($ im,2,10,30,' #ffff00 ',',' hello,world!',' # 103993 ';image png($ im);image destroy($ im);
-你好-你好PHP?服务器端编程语言(Professional Hypertext Preprocessor的缩写)朱庇特阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹阿齐兹。
版权声明:php实现了给图片添加笔画和马赛克的方法是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。