php產生小圖_php 產生縮圖代碼_PHP教程

來源:互聯網
上載者:User
php產生小圖_php 產生縮圖代碼 這是一款經典實用的產生小圖的php代碼,有專業素語來講就是php 產生縮圖代碼哦。

php教程產生小圖_php 產生縮圖代碼
這是一款經典實用的產生小圖的php代碼,有專業素語來講就是php 產生縮圖代碼哦。
*/


# 顯示圖形及串連

function showdir ($adirectory, $i)

{
global $browsedir;

$start = $i;

# 更改 $maxcols 及 $maximages 可改變每一頁顯示的小圖的行數與列數。

$maxcols = 2;
$maximages = 6;
$maximages = $i + ($maximages - 3);

# 更改 $imagemaxwidth 及 $imagemaxheight 可改變顯示小圖的寬度與高度。

$imagemaxwidth = 100;
$imagemaxheight = 100;

# 計算高度與寬度的比例。

$imagemaxratio = $imagemaxwidth / $imagemaxheight;

$ndirectory = sizeof ($adirectory);
echo (table_start);
for ($i; $i<=$maximages;)
{
echo (row_start);
for ($icols=1; $icols<=$maxcols; $icols++)
{
echo (col_start);
$imagefilename = $adirectory[++$i];
if (strlen($imagefilename)>0)
{
$imagepath = $browsedir."/".$imagefilename;
$imagesize = getimagesize ($imagepath);
if ($imagesize)
{
$imagewidth = $imagesize[0];
$imageheight = $imagesize[1];
$imageratio = $imagewidth / $imageheight;
if ($imageratio > $imagemaxratio)
{
$imageoutputwidth = $imagemaxwidth;
$imageoutputheight = ceil ($imagemaxwidth/$imagewidth*$imageheight);
}
else if ($imageratio < $imagemaxratio)
{
$imageoutputheight = $imagemaxheight;
$imageoutputwidth = ceil ($imagemaxheight/$imageheight*$imagewidth);
} else
{
$imageoutputwidth = $imagemaxwidth;
$imageoutputheight = $imagemaxheight;
}

# 顯示圖形

echo (a_start.$imagepath.a_close);
echo (img_start.$imagepath.img_width.$imageoutputwidth.img_height.$imageoutputheight.img_end);
echo (line_break.$adirectory[$i]);
echo (a_end);
}
echo (col_end);
}
}
echo (row_end);
}
echo (table_end);
pagemenu ($browsedir, $ndirectory, $start);

}

function pagemenu ($browsedir, $ndirectory, $pg) {

echo "

page:";

$pg_num = 1;

for ($img_num = 0; $img_num <= $ndirectory;) {

if ($pg == $img_num) {
echo " *$pg_num ";
} else {
echo " $pg_num ";
}

# 建立其他頁次的串連, 每頁顯示四張圖, 故頁數 $pg_num 每加 1 , $img_num 就加 4 。

$pg_num = $pg_num + 1;
$img_num = $img_num + 4;

}

echo "n";

}

function dirtoarray ($browsedir, $extensions)
{

$nextensions = sizeof ($extensions);
$idirectory = 0;
$directory = dir($browsedir);

while ($entry = $directory->read())
{
for ($i=1; $i<=$nextensions; $i++)
{
$compare = stristr ($entry, $extensions[$i]);
if (strlen($compare) == strlen($extensions[$i]))
{
$adirectory[++$idirectory] = $entry;
break;
}
}
}
$directory->close();
return $adirectory;
}

#主程式

#變數 $browsedir 為圖形檔案放置的位置。

$browsedir="./images";

# 允許瀏覽的圖形副檔名, 放置於數組中, 可自行增加。

$extensions[1] = "jpeg";
$extensions[2] = "jpg";
$extensions[3] = "gif";
$extensions[4] = "png";
showdir (dirtoarray ($browsedir, $extensions), $start);

define ("line_break", "
");
define ("table_start", "


n"); define ("table_end", "
n");
define ("row_start", " n");
define ("row_end", " n");
define ("col_start", " n ");
define ("col_end", "n n");
define ("img_start", "define ("img_end", ">");
define ("img_width", " width=");
define ("img_height", " height=");
define ("a_start", 'define ("a_close", '">');
define ("a_end", "");
?>

http://www.bkjia.com/PHPjc/633031.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/633031.htmlTechArticlephp產生小圖_php 產生縮圖代碼 這是一款經典實用的產生小圖的php代碼,有專業素語來講就是php 產生縮圖代碼哦。 php教程產生小圖_php 生...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.