ÈÕ³£ÕûÀíPHPÖмòµ¥µÄͼÐδ¦Àí(¾­µä)

5年以前  |  阅读数:1118 次  |  编程语言:PHP 

1.¼ÓÔØGD¿a

GD¿aÊÇÒ»¸o¿ªÅµÄ¶¯Ì¬´´½¨Í¼Ïñ¡¢Ô´´uÂe¹«¿ªµÄº¯Êý¿a£¬¿ÉÒÔ´Ó¹Ù½ÍøÕ¾http://www.boutell.com/gd´¦ÏÂÔØ¡£Ä¿Ç°£¬GD¿aÖ§³ÖGIF¡¢PNG¡¢JPEG¡¢WBMPºÍXBMµÈ¶aÖÖͼÏñ¸ñʽ£¬ÓÃÓÚ¶ÔͼÏñµÄ´¦Ài¡£

GD¿aÔÚPHP 5ÖÐÊÇĬÈÏ°²×°µÄ£¬µ«Òª¼¤»iGD¿a£¬±ØÐeÐÞ¸Äphp.iniÎļþ¡£½«¸ÃÎļþÖеġ°;extension=php_gd2.dll¡±Ñ¡ÏiÇ°µÄֺš°;¡±É¾³ý£¬±£´aeÐ޸ĺoµÄÎļþ²¢ÖØÐÂÆo¶¯ApacheþÎñÆ÷¼´¿ÉÉuЧ¡£

2.´´½¨Ò»¸o¼oµ¥µÄͼÏñ

ʹÓÃGD2º¯Êý¿a¿ÉÒÔʵÏÖ¸÷ÖÖͼÐÎͼÏñµÄ´¦Ài¡£´´½¨»­²¼ÊÇʹÓÃGD2º¯Êý¿aÀ´´´½¨Í¼ÏñµÄµÚÒ»²½£¬ÎÞÂÛ´´½¨Ê²Ã´ÑuµÄͼÏñ£¬Ê×Ïȶ¼ÐeÒª´´½¨Ò»¸o»­²¼£¬ÆaËu²Ù×÷¶¼½«ÔÚÕa¸o»­²¼ÉÏÍe³É¡£ÔÚGD2º¯Êý¿aÖд´½¨»­²¼£¬¿ÉÒÔͨ¹ýimagecreate()º¯ÊýʵÏÖ¡£

ʹÓÃimagecreate£¨£(C)º¯Êý´´½¨Ò»¸o¿i¶ÈΪ200ÏñËØ£¬¸ß¶ÈΪ60ÏñËصĻ­²¼£¬²¢ÉeÖû­²¼ÑÕÉ«RGB£¨225,66£¬159£(C)£¬×iºoÊa³oÒ»¸oGIF¸ñʽµÄͼÏñ£¬´uÂeÈçÏ£º


    <?php
    $im = imagecreate(200,60);           //´´½¨Ò»¸o»­²¼
    $white = imagecolorallocate($im, 225,66,159);   //ÉeÖû­²¼µÄ±³¾°ÑÕɫΪdzÂÌÉ«
    imagegif($im);                //Êa³oͼÏñ
    ?>

3.ʹÓÃGD2º¯ÊýÔÚÕÕƬÉÏÌi¼ÓÎÄ×Ö

PHPÖеÄGD¿aÖ§³ÖÖÐÎÄ£¬µ«±ØÐeÒªÒÔUTF-8¸ñʽµÄ²ÎÊýÀ´½øÐд«µÝ£¬Èç¹uʹÓÃimageString()º¯ÊýÖ±½Ó»aeÖÆÖÐÎÄ×Öu´®¾Í»aÏÔʾÂÒÂe£¬ÕaÊÇÒoΪGD2¶ÔÖÐÎÄÖ»ÄܽÓÊÕUTF-8±aÂe¸ñʽ£¬²¢ÇÒĬÈÏʹÓÃÓ¢ÎÄ×ÖÌa£¬ËuÒÔÒªÊa³oÖÐÎÄ×Öu´®£¬±ØÐe¶ÔÖÐÎÄ×Öu´®½øÐÐתÂe£¬²¢ÉeÖÃÖÐÎÄ×ÖuʹÓõÄ×ÖÌa¡£*ñÔo£¬Êa³oµÄÖ»ÄÜÊÇÂÒÂe¡£

ʹÓÃimageTTFText£¨£(C)º¯Êý½«ÎÄ×Ö¡°ÕaÊÇÒ»¸o²aÊÔ¡±Êa³oµ½Í¼ÏñÖУ¬´uÂeÈçÏ£º


    <?php
    header("content-type:image/jpeg");    //¶¨ÒaÊa³oΪͼÏñÀaÐÍ
    $im=imagecreatefromjpeg("images/photo.jpg");    //ÔØÈeÕÕƬ
    $textcolor=imagecolorallocate($im,56,73,136);//ÉeÖÃ×ÖÌaÑÕɫΪÀ¶É«£¬ÖµÎªRGBÑÕÉ«Öµ
    $fnt="c:/windows/fonts/simhei.ttf";   //¶¨Òa×ÖÌa
    $motto=iconv("gb2312","utf-8","ÕaÊÇÒ»¸o²aÊÔ");   //¶¨ÒaÊa³o×ÖÌa´®
    imageTTFText($im,220,0,480,340,$textcolor,$fnt,$motto);   //дTTFÎÄ×Öµ½Í¼ÖÐ
    imagejpeg($im);    //½¨Á¢JPEGͼÐÎ
    imagedestroy($im);  //½aÊøͼÐΣ¬ÊÍ*ÅÄÚ´ae¿Õ¼a
    ?>

4.PHPÉu³ÉÑeÖ¤Âe

´´½¨Ò»¸ochecks.phpÎļþÔÚÎļþÖÐʹÓÃGD2º¯Êý´´½¨Ò»¸o4λµÄÑeÖ¤Âe£¬²¢½«Éu³ÉµÄÑeÖ¤Âe±£´aeµ½sessionÖУº


    <?php
    session_start();
    header("content-type:image/png");    //ÉeÖô´½¨Í¼ÏñµÄ¸ñʽ
    $image_width=70;           //ÉeÖÃͼÏñ¿i¶È
    $image_height=18;           //ÉeÖÃͼÏñ¸ß¶È
    srand(microtime()*100000);        //ÉeÖÃËae»uÊýµÄÖÖ×Ó
    for($i=0;$i<4;$i++){         //Ñ­»*Êa³oÒ»¸o4λµÄËae»uÊý
      $new_number.=dechex(rand(0,15));
    }
    $_SESSION[check_checks]=$new_number;  //½«»ñÈ¡µÄËae»uÊýÑeÖ¤ÂeдÈeµ½SESSION±aÁ¿ÖÐ   

    $num_image=imagecreate($image_width,$image_height); //´´½¨Ò»¸o»­²¼
    imagecolorallocate($num_image,255,255,255);     //ÉeÖû­²¼µÄÑÕÉ«
    for($i=0;$i<strlen($_SESSION[check_checks]);$i++){ //Ñ­»*¶ÁÈ¡SESSION±aÁ¿ÖеÄÑeÖ¤Âe
      $font=mt_rand(3,5);                //ÉeÖÃËae»uµÄ×ÖÌa
      $x=mt_rand(1,8)+$image_width*$i/4;        //ÉeÖÃËae»u×Ö*uËuÔÚλÖõÄX×ø±e
      $y=mt_rand(1,$image_height/4);          //ÉeÖÃËae»u×Ö*uËuÔÚλÖõÄY×ø±e
      $color=imagecolorallocate($num_image,mt_rand(0,100),mt_rand(0,150),mt_rand(0,200));    //ÉeÖÃ×Ö*uµÄÑÕÉ«
      imagestring($num_image,$font,$x,$y,$_SESSION[check_checks][$i],$color);           //ˮƽÊa³o×Ö*u
    }
    imagepng($num_image);         //Éu³ÉPNG¸ñʽµÄͼÏñ
    imagedestroy($num_image);       //ÊÍ*ÅͼÏñ×ÊÔ´
    ?>

´´½¨Ò»¸oÓû§µÇ¼µÄ±iµ¥²¢µ÷ÓÃchecks.phpÔÚ±iµ¥ÖÐÊa³oͼÏñµÄÄÚÈÝ£º


    <?php
    session_start();
    if($_POST["Submit"]!=""){
    $checks=$_POST["checks"];
    if($checks==""){
    echo "<script> alert('ÑeÖ¤Âe²»ÄÜΪ¿Õ');window.location.href='index.php';</script>";
    }
    if($checks==$_SESSION[check_checks]){
      echo "<script> alert('Óû§µÇ¼³É¹¦!');window.location.href='index.php';</script>";
    }else{
      echo "<script> alert('ÄuÊaÈeµÄÑeÖ¤Âe²»ÕýÈ*!');window.location.href='index.php';</script>";
    }
    }
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>randº¯ÊýµÄÓ¦ÓÃ</title>
    <style type="text/css">
    <!--
    .STYLE1 {
      font-size: 12px;
      color: #FFFFFF;
      font-weight: bold;
    }
    .style2 {font-weight: bold; font-size: 12px;}
    -->
    </style>
    </head>
    <body>
    <form name="form" method="post" action="">
     <table width="1003" border="0" cellspacing="0" cellpadding="0">
      <tr>
       <td width="168" height="169" background="images/index_01.gif"> </td>
       <td width="685" background="images/index_02.gif"> </td>
       <td width="150" background="images/index_03.gif"> </td>
      </tr>
      <tr>
       <td width="168" height="311" background="images/index_04.gif"> </td>
       <td background="images/index_05.gif"><table width="675" height="169" border="0" cellpadding="0" cellspacing="0">
        <tr>
         <td height="43" align="center" valign="baseline"> </td>
         <td align="center" valign="middle"> </td>
         <td align="center" valign="baseline"> </td>
        </tr>
        <tr>
         <td width="382" height="24" align="center" valign="baseline"> </td>
         <td width="207" height="24" valign="middle"><span class="style2">Óû§Ãu</span><span class="STYLE1">
          <input name="txt_user" id="txt_user" style="height:20px " size="10">
           </span></td>
         <td width="86" height="24" align="center" valign="baseline"> </td>
        </tr>
        <tr>
         <td height="24" align="center" valign="baseline"> </td>
         <td height="24" valign="middle"><span class="style2">ÃܤuÂe</span><span class="STYLE1">
         <input name="txt_pwd" type="password" id="txt_pwd" style="FONT-SIZE: 9pt; height:20px" size="10">
         </span></td>
         <td height="24" align="center" valign="baseline"> </td>
        </tr>
        <tr>
         <td height="24" align="center" valign="baseline"> </td>
         <td height="24" valign="middle"><span class="style2">ÑeÖ¤Âe</span><span class="STYLE1">
         <input name="checks" size="6" style="height:20px ">
         <img src="checks.php" width="70" height="18" border="0" align="bottom"></span>  </td>
         <td height="24" align="center" valign="baseline"> </td>
        </tr>
        <tr>
         <td height="40" align="center" valign="baseline"> </td>
         <td align="center" valign="baseline">    <input type="submit" name="Submit" value="怬"></td>
         <td align="center" valign="baseline"> </td>
        </tr>
       </table></td>
       <td background="images/index_06.gif"> </td>
      </tr>
      <tr>
       <td height="100"> </td>
       <td> </td>
       <td> </td>
      </tr>
     </table>
    </form>
    </body>
    </html>

ÒÔÉÏÄÚÈÝÊÇС±a¸ø´o¼Ò*ÖÏiµÄÓйØphpÖмoµ¥µÄͼÐδ¦Ài£¬Ï£Íu´o¼Òϲ»¶¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例