All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
C#网络应用编程基础练习题与答案(三)_.net资料_编程技术
数据库人员手边系列:SQL Server安全列表_[SQL Server教程]
用ADO管理SQL,Server数据库_[SQL,Server教程]
让我们来编写一些PHP实用的脚本_php资料_编程技术
asp.net各种日期操作大全_[Asp.Net教程]
WAP与PHP程序设计之基础篇_[PHP教程]
PHP5.2.3连接,SQLSERVER,注意事项_php资料_编程技术
ASP.NET应用技巧:AspNetForums的数据层概述_.net资料_编程技术
使用MD5变换算法来防止穷举破译密码_[Asp.Net教程]
ajax和asp.net的配置文件_[Asp.Net教程]
Reading number is top 10 pictures
The Soviet union swimsuit exposure in the 70 year1
两个妞在等世界上最短的火车
Chinese paper-cut grilles art appreciation5
Female model behind the bitterness, often being overcharged4
Startling Russian girl blind date scene1
美女和狗狗1
牛奶和人奶哪个好?
战场废物2
中国女孩大胆自拍,显露完美身材2
The goddess of the single reason2
Download software ranking
Macromedia Dreamweaver 8
Tram sex maniac 2 (H) rar bag13
Popkart Cracked versions Mobile phone games
Tram sex maniac 2 (H) rar bag5
Unix video tutorial8
Unix video tutorial7
株洲本地在线棋牌游戏
Tram sex maniac 2 (H) rar bag4
网络管理员第三版
Visual C++界面编程技术
归海一刀 published in(发表于) 2014/2/17 7:31:36 Edit(编辑)
PHP实例:PHP批量生成缩略图_[PHP教程]

PHP实例:PHP批量生成缩略图_[PHP教程]

PHP实例:PHP批量生成缩略图_[PHP教程]

到今天我学PHP已经快一年了。不过小弟资质相当有限,一直没有做出什么好东西来。在工作中有时需要把大批量的图片变小,这是一件很简单但很无聊的事情。有一天突发奇想,怎么不用PHP来做一个小程序呢?于是昨天完成了一个批量生成缩略图的小程序。现在发布出来,请各位大哥大姐多多批评!
­
1.先来分析一下程序的界面。
界面很简单:首先声明本程序仅支持JPG、GIF、PNG三种图片格式。然后分别指出源文件和缩略图保存的文件夹。接下来可以设置JPG的质量和缩量图的大小。最后是显示所消耗的时间和处理的图片数。
2.完整PHP源程序。源程序很简单,不多做解释。解压后直接放于可运行PHP的WWW目录下既可运行。
­
function microtimeFloat()
{
list(uSecond, second) = explode(" ", microtime());
return ((float)uSecond + (float)second);
}
dirFlag = pathinfo(_SERVER['scrīpt_FILENAME'],PATHINFO_DIRNAME);
timeStart = microtimeFloat();
sourcesDir = 'sources/';
thumbsDir = 'thumbs/';
jpgQuality = _POST['jpgQuality'];
thumbWidth = _POST['thumbWidth'];
counter = 0;
if(handle = opendir(sourcesDir)) {
while(imageName = readdir(handle)) {
FileExtName = strtolower(pathinfo(imageName, PATHINFO_EXTENSION));
if((FileExtName == 'gif') or (FileExtName == 'jpg') or (FileExtName == 'jpeg') or (FileExtName == 'png')) {
thumbsUrl = thumbsDir.imageName;
list(realWidth, realHeight) = getimagesize(sourcesDir.imageName);
if(realWidth < thumbWidth){
percent = 1;
} else {
percent = thumbWidth / realWidth;
}
newWidth = realWidth * percent;
newHeight = realHeight * percent;
currentThumb = imagecreatetruecolor(newWidth, newHeight);
list(width, height, pictureType, attrib) = getimagesize(sourcesDir.imageName);
switch(pictureType)
{
case "1": source = imagecreatefromgif(sourcesDir.imageName); break;
case "2": source = imagecreatefromjpeg(sourcesDir.imageName); break;
case "3": source = imagecreatefrompng(sourcesDir.imageName); break;
}
imagecopyresized(currentThumb, source, 0, 0, 0, 0, newWidth, newHeight, realWidth, realHeight);
switch(pictureType)
{
case "1": imagegif(currentThumb, thumbsUrl); break;
case "2": imagejpeg(currentThumb, thumbsUrl, jpgQuality); break;
case "3": imagepng(currentThumb, thumbsUrl); break;
}
counter++;
}
}
closedir(handle);
timeEnd = microtimeFloat();
execTime = round(timeEnd - timeStart, 2);
}
?>




批量生成缩略图

















批量生成缩略图






本程序仅支持JPG、GIF、PNG三种图片格式。






请将源文件放于:






缩略图将保存于:






JPG质量:

请输入JPG质量仅接受整数请不要输入大于100的整数







缩略图大小:

请输入缩略图大小仅接受整数
< /td>



































来源:csdn







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.