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

首頁 > 語言 > PHP > 正文

php 生成縮略圖代碼

2024-09-04 11:44:21
字體:
供稿:網(wǎng)友

這是一款經(jīng)典實用的生成小圖的php代碼,有專業(yè)素語來講就是php 生成縮略圖代碼,實例代碼如下:

  1. # 顯示圖形及連接 
  2. function showdir ($adirectory$i
  3. {  
  4.   global $browsedir
  5.  
  6.   $start = $i
  7.  
  8. # 更改 $maxcols 及 $maximages 可改變每一頁顯示的小圖的行數(shù)與列數(shù)。 
  9.  
  10.   $maxcols = 2;  
  11.   $maximages = 6;  
  12.   $maximages = $i + ($maximages - 3); 
  13.  
  14. # 更改 $imagemaxwidth 及 $imagemaxheight 可改變顯示小圖的寬度與高度。 
  15.  
  16.   $imagemaxwidth = 100;  
  17.   $imagemaxheight = 100;  
  18.      
  19. # 計算高度與寬度的比例。 
  20.  
  21.   $imagemaxratio =  $imagemaxwidth / $imagemaxheight;  
  22.      
  23.   $ndirectory = sizeof ($adirectory);  
  24.   echo (table_start);  
  25.   for ($i$i<=$maximages;)  
  26.   {  
  27.      echo (row_start);  
  28.      for ($icols=1; $icols<=$maxcols$icols++)  
  29.      {  
  30.        echo (col_start);  
  31.        $imagefilename = $adirectory[++$i];  
  32.        if (strlen($imagefilename)>0)  
  33.        {  
  34.          $imagepath = $browsedir."/".$imagefilename;  
  35.          $imagesize = getimagesize ($imagepath);  
  36.          if ($imagesize)  
  37.          {  
  38.            $imagewidth = $imagesize[0];  
  39.            $imageheight = $imagesize[1];  
  40.            $imageratio = $imagewidth / $imageheight;  
  41.            if ($imageratio > $imagemaxratio)  
  42.            {  
  43.               $imageoutputwidth = $imagemaxwidth;  
  44.               $imageoutputheight = ceil ($imagemaxwidth/$imagewidth*$imageheight);  
  45.            }  
  46.            else if ($imageratio < $imagemaxratio)  
  47.            {  
  48.               $imageoutputheight = $imagemaxheight;  
  49.               $imageoutputwidth = ceil ($imagemaxheight/$imageheight*$imagewidth);  
  50.            } else  
  51.            {  
  52.               $imageoutputwidth = $imagemaxwidth;  
  53.               $imageoutputheight = $imagemaxheight;  
  54.            } 
  55.  
  56. # 顯示圖形 
  57.  
  58.            echo (a_start.$imagepath.a_close);  
  59.            echo (img_start.$imagepath.img_width.$imageoutputwidth.img_height.$imageoutputheight.img_end);  
  60.            echo (line_break.$adirectory[$i]);  
  61.            echo (a_end);  
  62.          }  
  63.          echo (col_end);  
  64.        }  
  65.      }  
  66.      echo (row_end);  
  67.   }  
  68.   echo (table_end);  
  69. pagemenu ($browsedir$ndirectory$start); 
  70.  
  71.  
  72. function pagemenu ($browsedir$ndirectory$pg) { 
  73.  
  74. echo "<br><center><font face="verdana, arial, helvetica, sans-serif" size="1" color="#000033">page:"
  75.  
  76. $pg_num = 1; 
  77. //開源代碼Vevb.com 
  78. for ($img_num = 0; $img_num <= $ndirectory;) { 
  79.  
  80.     if ($pg == $img_num) { 
  81.     echo "<span class="menulink_1"><a href="thumb.php?browsedir=$browsedir&start=$img_num"> *$pg_num</a> <span>";  
  82.     } else {  
  83.     echo "<span class="menulink_2"><a href="thumb.php?browsedir=$browsedir&start=$img_num"> $pg_num</a> <span>";  
  84.     } 
  85.  
  86. # 建立其他頁次的連接, 每頁顯示四張圖, 故頁數(shù) $pg_num 每加 1 , $img_num 就加 4 。 
  87.  
  88.     $pg_num = $pg_num + 1;  
  89.     $img_num = $img_num + 4; 
  90.  
  91.  
  92. echo "</font> "
  93.  
  94.  
  95. function dirtoarray ($browsedir$extensions)  
  96.  
  97.   $nextensions = sizeof ($extensions);  
  98.   $idirectory = 0;  
  99.   $directory = dir($browsedir);  
  100.      
  101.   while ($entry = $directory->read())  
  102.   {  
  103.       for ($i=1; $i<=$nextensions$i++)  
  104.       {  
  105.          $compare = stristr ($entry$extensions[$i]);  
  106.          if (strlen($compare) == strlen($extensions[$i]))  
  107.          {  
  108.             $adirectory[++$idirectory] = $entry;  
  109.             break;  
  110.          }  
  111.       }  
  112.   }  
  113.   $directory->close(); 
  114.   return $adirectory;  
  115.  
  116. #主程序 
  117.  
  118. #變量 $browsedir 為圖形文件放置的位置。 
  119.  
  120. $browsedir="./images"
  121.  
  122. # 允許瀏覽的圖形文件擴展名, 放置於數(shù)組中, 可自行增加。 
  123.  
  124. $extensions[1] = "jpeg";  
  125. $extensions[2] = "jpg";  
  126. $extensions[3] = "gif";  
  127. $extensions[4] = "png";   
  128. showdir (dirtoarray ($browsedir$extensions), $start); 
  129.  
  130. define ("line_break""<br>");  
  131. define ("table_start""<table width=600> ");  
  132. define ("table_end""</table> ");  
  133. define ("row_start""  <tr> ");  
  134. define ("row_end""  </tr> ");  
  135. define ("col_start""   <td align=center>       ");  
  136. define ("col_end""    </td> ");  
  137. define ("img_start""<img src=");  
  138. define ("img_end"">");  
  139. define ("img_width"" width=");  
  140. define ("img_height"" height=");  
  141. define ("a_start"'<a href="');  
  142. define ("a_close"'">');  
  143. define ("a_end""</a>"); 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 保定市| 万山特区| 武山县| 东平县| 施秉县| 桓台县| 新津县| 江山市| 雷山县| 原平市| 五台县| 长丰县| 枣庄市| 乌兰察布市| 肥乡县| 通州区| 南华县| 女性| 前郭尔| 太白县| 汉源县| 宁强县| 扎鲁特旗| 正定县| 山西省| 怀来县| 那曲县| 定远县| 甘肃省| 女性| 新和县| 怀来县| 甘肃省| 泽库县| 四川省| 阳城县| 册亨县| 长子县| 新兴县| 离岛区| 奉新县|