国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php生成圖片與驗證碼圖片生成原理

2024-09-04 11:44:24
字體:
來源:轉載
供稿:網友

這款php生成圖片與驗證碼圖片生成原理代碼,是由php gd庫來支持,如果你的系統不能創建圖片就把gd.dll前面的;去再,重起apache,如果是iis重起iis就OK了.創建圖片后記得用ImageDestroy 清空內存.

php生成圖片與驗證碼圖片實例代碼如下:

  1. $w?$RESIZEWIDTH=$w:$RESIZEWIDTH=400;// 生成圖片的寬度 
  2. $h?$RESIZEHEIGHT=$h:$RESIZEHEIGHT=400;// 生成圖片的高度 
  3. function ResizeImage($im,$maxwidth,$maxheight,$name){ 
  4.     $width = imagesx($im); 
  5.     $height = imagesy($im); 
  6.     if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){ 
  7.         if($maxwidth && $width > $maxwidth){ 
  8.             $widthratio = $maxwidth/$width
  9.             $RESIZEWIDTH=true;//m.survivalescaperooms.com 
  10.         } 
  11.         if($maxheight && $height > $maxheight){ 
  12.             $heightratio = $maxheight/$height
  13.             $RESIZEHEIGHT=true; 
  14.         } 
  15.         if($RESIZEWIDTH && $RESIZEHEIGHT){ 
  16.             if($widthratio < $heightratio){ 
  17.                 $ratio = $widthratio
  18.             }else
  19.                 $ratio = $heightratio
  20.             } 
  21.         }elseif($RESIZEWIDTH){ 
  22.             $ratio = $widthratio
  23.         }elseif($RESIZEHEIGHT){ 
  24.             $ratio = $heightratio
  25.         } 
  26.         $newwidth = $width * $ratio
  27.         $newheight = $height * $ratio
  28.         if(function_exists("imagecopyresampled")){ 
  29.               $newim = imagecreatetruecolor($newwidth$newheight); 
  30.               imagecopyresampled($newim$im, 0, 0, 0, 0, $newwidth$newheight$width$height); 
  31.         }else
  32.             $newim = imagecreate($newwidth$newheight); 
  33.               imagecopyresized($newim$im, 0, 0, 0, 0, $newwidth$newheight$width$height); 
  34.         } 
  35.         ImageJpeg ($newim,$name); 
  36.         ImageDestroy ($newim); 
  37.     }else
  38.         ImageJpeg ($im,$name); 
  39.     } 
  40. }  
  41.  
  42. if($_FILES['uploadfile']['size']){ 
  43.     if($_FILES['uploadfile']['type'] == "image/pjpeg"){ 
  44.         $im = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']); 
  45.     }elseif($_FILES['uploadfile']['type'] == "image/x-png"){ 
  46.         $im = imagecreatefrompng($_FILES['uploadfile']['tmp_name']); 
  47.     }elseif($_FILES['uploadfile']['type'] == "image/gif"){ 
  48.         $im = imagecreatefromgif($_FILES['uploadfile']['tmp_name']); 
  49.     } 
  50.     if($im){ 
  51.         if(file_exists('bbs.jpg')){ 
  52.             unlink('m.survivalescaperooms.com.jpg'); 
  53.         } 
  54.         ResizeImage($im,$RESIZEWIDTH,$RESIZEHEIGHT,'bbs.jpg'); 
  55.         ImageDestroy ($im); 
  56.    
  57.     } 
  58. //$uploadfile="bbs.jpg"; 
  59.   

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 五河县| 铁力市| 黄龙县| 达拉特旗| 敦化市| 余庆县| 青铜峡市| 屯昌县| 沁水县| 锡林浩特市| 太湖县| 封开县| 仁怀市| 虞城县| 上思县| 桂林市| 通渭县| 合阳县| 珠海市| 江北区| 罗城| 偏关县| 肃宁县| 大洼县| 科技| 麻阳| 敖汉旗| 施甸县| 青冈县| 农安县| 阿拉善盟| 都匀市| 乐安县| 永年县| 日喀则市| 尤溪县| 阳西县| 海城市| 佳木斯市| 林甸县| 江安县|