当前位置: 首页 > 图文教程 > 网络编程 > PHP > 生成缩略图

PHP
Php部分常见问题总结
从零开始 教你如何搭建Discuz!4.1论坛(图)
php分页函数
php计数器的设计与实现
PHP初学者头疼问题总结
WinXP + Apache +PHP5 + MySQL + phpMyAdmin安装全功略
PHP截取中文字符串的问题
删除无限级目录与文件代码共享
生成静态页面的PHP类
转换中文为unicode 转换unicode到正常文本
玩转图像函数库—常见图形操作
Windows下PHP5和Apache的安装与配置
apache+mysql+php+ssl服务器之完全安装攻略
PHP.MVC的模板标签系统(一)
PHP.MVC的模板标签系统(二)
PHP.MVC的模板标签系统(三)
PHP.MVC的模板标签系统(四)
PHP.MVC的模板标签系统(五)
Windows下的PHP5.0安装配制详解
PHP中的串行化变量和序列化对象

PHP 中的 生成缩略图


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 96 ::
收藏到网摘: n/a


生成缩略图 $tx=GetImageSize($sample);
if($tx[0]<=$tx[1] and $tx[1]>=120){
$height=120;
$width=intval($height*$tx[0]/$tx[1]);
}
if($tx[0]>=$tx[1] and $tx[0]>=100){
$width=100;
$height=intval($width*$tx[1]/$tx[0]);
}
if($tx[0]<100 and $tx[1]<120){
$width=$tx[0];
$height=$tx[1];
}
makethumb2($sample,$target,$width,$height);
// $srcFile: 源文件
// $dstFile: 目标文件
// $dstW: 目标图片宽度
// $dstH: 目标文件高度
function makethumb2($srcFile,$dstFile,$dstW,$dstH){
$data=GetImageSize($srcFile,&$info);
switch($data[2]){
case 1:
$im=@ImageCreateFromGIF($srcFile);
break;
case 2:
$im=@ImageCreateFromJPEG($srcFile);
break;
case 3:
$im=@ImageCreateFromPNG($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
$ni=ImageCreate($dstW,$dstH);
ImageCopyResized($ni,$im,0,0,0,0,$dstW,$dstH,$srcW,$srcH);
ImageJpeg($ni,$dstFile);
// 如果需要输出到浏览器,那么将上一句改为ImageJpeg($ni);
// 如果需要其它格式的图片,改动最后一句就可以了
}