时间:2021-07-01 10:21:17 帮助过:2人阅读
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 ($adirectoryhttps://www.gxlcms.com/);
echo (table_starthttps://www.gxlcms.com/);
for ($i; $i<=$maximages;)
{
echo (row_starthttps://www.gxlcms.com/);
for ($icols=1; $icols<=$maxcols; $icols++)
{
echo (col_starthttps://www.gxlcms.com/);
$imagefilename = $adirectory[++$i];
if (strlen($imagefilename)>0)
{
$imagepath = $browsedir."/".$imagefilename;
$imagesize = getimagesize ($imagepathhttps://www.gxlcms.com/);
if ($imagesize)
{
$imagewidth = $imagesize[0];
$imageheight = $imagesize[1];
$imageratio = $imagewidth / $imageheight;
if ($imageratio > $imagemaxratio)
{
$imageoutputwidth = $imagemaxwidth;
$imageoutputheight = ceil ($imagemaxwidth/$imagewidth*$imageheighthttps://www.gxlcms.com/);
}
else if ($imageratio < $imagemaxratio)
{
$imageoutputheight = $imagemaxheight;
$imageoutputwidth = ceil ($imagemaxheight/$imageheight*$imagewidthhttps://www.gxlcms.com/);
} else
{
$imageoutputwidth = $imagemaxwidth;
$imageoutputheight = $imagemaxheight;
}# 显示图形
echo (a_start.$imagepath.a_closehttps://www.gxlcms.com/);
echo (img_start.$imagepath.img_width.$imageoutputwidth.img_height.$imageoutputheight.img_endhttps://www.gxlcms.com/);
echo (line_break.$adirectory[$i]https://www.gxlcms.com/);
echo (a_endhttps://www.gxlcms.com/);
}
echo (col_endhttps://www.gxlcms.com/);
}
}
echo (row_endhttps://www.gxlcms.com/);
}
echo (table_endhttps://www.gxlcms.com/);
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 每加 1 , $img_num 就加 4 。
$pg_num = $pg_num + 1;
$img_num = $img_num + 4;}
echo "
n";}
function dirtoarray ($browsedir, $extensions)
{$nextensions = sizeof ($extensionshttps://www.gxlcms.com/);
$idirectory = 0;
$directory = dir($browsedirhttps://www.gxlcms.com/);
while ($entry = $directory->read())
{
for ($i=1; $i<=$nextensions; $i++)
{
$compare = stristr ($entry, $extensions[$i]https://www.gxlcms.com/);
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", "
"https://www.gxlcms.com/);
define ("table_start", "n"https://www.gxlcms.com/);
n"https://www.gxlcms.com/);
define ("table_end", "
define ("row_start", "n"https://www.gxlcms.com/); n"https://www.gxlcms.com/);
define ("row_end", "
define ("col_start", "n "https://www.gxlcms.com/); n"https://www.gxlcms.com/);
define ("col_end", "n
define ("img_start", ""https://www.gxlcms.com/);
define ("img_width", " width="https://www.gxlcms.com/);
define ("img_height", " height="https://www.gxlcms.com/);
define ("a_start", ' define ("a_close", '">'https://www.gxlcms.com/);
define ("a_end", ""https://www.gxlcms.com/);
?>
http://www.bkjia.com/PHPjc/633031.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/633031.htmlTechArticlephp生成小图_php 生成缩略图代码 这是一款经典实用的生成小图的php代码,有专业素语来讲就是php 生成缩略图代码哦。 php教程生成小图_php 生...