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

PHP
NT IIS下用ODBC连接数据库
基于mysql的bbs设计(三)
基于mysql的bbs设计(二)
基于mysql的bbs设计(一)
PHP+DBM的同学录程序(2)
PHP+DBM的同学录程序(3)
基于mysql的bbs设计(四)
PHP+DBM的同学录程序(1)
PHP+DBM的同学录程序(4)
同时提取多条新闻中的文本一例
PHP+DBM的同学录程序(5)
基于mysql的bbs设计(五)
杏林同学录(二)
杏林同学录(一)
php访问查询mysql数据的三种方法
实时抓取YAHOO股票报价的代码
模拟SQLSERVER的两个函数:dateadd(),datediff()
如何实现给定日期的若干天以后的日期
一个SQL管理员的web接口
利用PHP动态生成VRML网页

PHP 中的 生成缩略图


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 105 ::
收藏到网摘: 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);
// 如果需要其它格式的图片,改动最后一句就可以了
}