PHP验证码生成及图片处理(GD库)

前端之家收集整理的这篇文章主要介绍了PHP验证码生成及图片处理(GD库)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

GD库是PHP处理图形的扩展库,GD库提供了一系列用来处理图片的API,使用GD库可以处理图片,或者生成图片,也可以给图片加水印。

本章实现了生成图片并绘画各种形状、图片的压缩、中文字符水印及图片水印、基本验证码的生成和使用。对强大的GD库有基本的了解和使用。

 GD库支持图片格式:

PNG:

生成图片显示显示最好

是一种无损压缩的位图片形格式

GIF:

生成图片显示显示较好

GIF是一种基于LZW算法的连续色调的无损无损压缩格式

JPEG:

一种标准的压缩名称,通常用来存储照片或者存储具有丰富色彩和色彩层次的图像,格式使用了有损压缩。

.....

<p align="left">各种图形绘画和文字显示


<div class="cnblogs_code">

 
 =imagecreatetruecolor(500,500 
 图片资源,R,G,B)
 =imagecolorallocate(,255 =imagecolorallocate(,255,0 =imagecolorallocate(,0 =imagecolorallocate(,255 
 图片资源,x,y,颜色)
 
 imagefill(, 
 图片资源,起始x,起始y,终点x,终点y,颜色)
 imageline(,10,20,100, 
 图片资源,左上角x,右下角x,y,颜色)
 
 imagerectangle(,50, 
 imagefilledrectangle(, 
 
 imageellipse(, imagefilledellipse(, 
 
 imagearc(,120,110,-180,  
 
 ="DONGxiaoDONG" 
 imagestring(,5,330,, 
 内容)
 ="东小东" imagettftext(,200,300,,"font/xy.ttf", 
 
 
  
 imagejpeg(,"xxx.jpg" 
 
 imagedestroy();

图片的压缩及裁剪:

PHP 图片 openimg( 图片信息,宽,高,类型 =( (,,)= 图片类型为1,2,3,所以需要0占位 =("占位/必须","gif","jpeg","png" 函数 ="imagecreatefrom".[ 图片资源 =( =imagecolorallocate(,0 内容) ="东小东" imagettftext(,-100,-100,, =100 =100 =imagecreatetruecolor(, (&&(< =(/)* } =(/)* =imagecolorallocate(,255); imagecolortransparent(,); imagefill(,); 输出资源,原资源,目标起始点(x,y),原起始点,目标长高,原长高) imagecopyresampled(,,,,, 函数相同,注意原大小应设置为目标大小 ="image".[ (, (,"new". ">" "" imagedestroy( imagedestroy( 调用函数 =openimg("zcy.gif");

文字图片水印的生成

图片 openimg( 图片信息,宽,高,类型 =( (,)= 图片类型为1,3,所以需要0占位 =("占位/必须","png" 函数 ="imagecreatefrom".[ 图片资源 =( =imagecolorallocate(,0 文字水印 内容) ="东 小 东" 中文utf8占3个字节 =()/3*imagefontwidth(7 =imagefontheight(7 imagettftext(,7,--10,-, 图片水印 =imagecreatefromgif("zcy.gif" 图片信息,宽,高,类型 =("zcy.gif" (,)= 图片水印,参数(原图片资源,水印图片资源,原图片开始位置x,水印图片开始x,宽,高) imagecopy(,,, ="image".[ (,"new". ">" imagedestroy( imagedestroy( 调用函数 =openimg("xxx.png");

验证码的生成及使用详细:

PHP =imagecreatetruecolor(80,30 =imagecolorallocate(,100 =imagecolorallocate(,0 =imagecolorallocate(,0 =imagecolorallocate(,255 随机背景颜色 =imagecolorallocate(,(200,255),(100,150),255 imagefill(, 图片资源,起始x,颜色) imageline(,30, imageline(,15,80,6, 图片资源,左上角x,右下角x,y,颜色) imagerectangle(,80-1,30-1, 生成验证码随机字符 ="3456789abcdefghkmnpqrstvuywzABCDEFGHIGKLMNPQRSTVUYWZ" ="" (=0;<4;++ .=[(0,()-1 内容) ="东小". imagettftext(,, imagettftext(, imagettftext(,11,, ["codex"]= 输出,imagejpeg ("Content-type:image/png" imagepng( imagedestroy();

显示:

<div class="cnblogs_code">

   PHP"
      
      
       
       
      PHP"PHP'"
       
      上传"    
   

获取:

<div class="cnblogs_code">

   "验证码字符串为:".["codex"]."
" "输入的验证码为:".["codeyy"];


猜你在找的PHP相关文章