您好,欢迎访问一九零五行业门户网

深入探讨PHP生成缩略图的实现方法_PHP教程

我们在运用
php生成缩略图html代码
!doctype html public -//w3c//dtd html 4.0 transitional//en>   html>   head>   title> 上传图片  /title>   meta name=generator content=editplus>   meta name=author content=>   meta name=keywords content=>   meta name=description content=>   meta http-equiv=content-type content=text/html; charset=gbk />   /head>     body>   form method=post action=tu.php?act=upload enctype=multipart/form-data >   p> input type=file name=file/> /p>   p> input type=submit value=hao/>   input type=reset/> /p>   /form>   /body>   /html>
php生成缩略图php代码
?php  /*后台登陆界面  *黄春龙学习编写  *首写时间:2009-10-27  *更新时间:2009/11/24  */  require_once '../xmphp/init.php';//全站配置文件  require_once xmphp_common.'/smarty.php';//smarty功能  require_once xmphp_common.'/mysql.php';//mysql功能  require_once xmphp_common.'/func.php';//常用函数  if(isset($_get['act'])&&$_get['act']
=='upload'){  $file=$_files['file'];  $info=pathinfo($file['name']);  $a=array('jpg','gif','png');  if(!in_array($info['extension'],$a)){  alert(请选择jpg,gif,png格式的图片
进行上传);  exit;  }  if($file['name'] !=''){  $dirname=date('ym');  $dirname='../upload/'.$dirname;//原图路径  $xin=$dirname.'/s';//php生成缩略图路径  if(!file_exists($xin)){  @mkdir($xin);  }  $image1=$info['filename'].'120_120'.'.'
.$info['extension'];//缩略图名称  $image2=$info['filename'].'300_300'.'.'
.$info['extension'];//缩略图名称  list($imagw,$imagh)=getimagesize($file
['tmp_name']);//取得原图的宽高(另外$file
['tmp_name']只是一个临时文件路径,有时可能
会报错,如报错只需把临时文件路径改成你上传
后的原图的路径即可)  //120图判断各种情况来取得缩略图的宽高  if($imagw =120&&$imagh =120){  $m120w=$imagw;  $m120h=$imagh;  }elseif($imagw>$imagh)  {  $m120w=120;  $m120h=intval($m120w/number_format(
$imagw/$imagh,2));//缩略图的宽除以(原
图的宽除以原图的高)number_format查手册  }  else  {  $m120h=300;  $m120w=intval($m120h/number_format(
$imagh/$imagw,2));//缩略图的高除以(原图
的高除以原图的宽)number_format查手册  }  //300图判断各种情况来取得缩略图的宽高  if($imagw =300&&$imagh =300){  $m300w=$imagw;  $m300h=$imagh;  }elseif($imagw>$imagh){  $m300w=300;  $m300h=intval($m300w/number_format(
$imagw/$imagh,2));//缩略图的宽除以(原
图的宽除以原图的高)number_format查手册  }else{  $m300h=300;  $m300w=intval($m300h/number_format(
$imagh/$imagw,2));//缩略图的高除以(原
图的高除以原图的宽)number_format查手册  }  if($info['extension']=='jpg'){  $info['extension']='jpeg';//判断图像类
型如果是jpg的则把它转换成jpeg的因为图像处
理函数在处理jpg的时候都是用的jpeg而不是jpg  }  $iml='imagecreatefrom'.$info['extension'];//取得不同图片格式的不同函数  $yuan=$iml($file['tmp_name']);//根据前面取的不同函数来取的原图的标识  $mu1=imagecreatetruecolor($m120w,$m120h);//取的要生成的缩略图的标识  $mu2=imagecreatetruecolor($m300w,$m300h);//取的要生成的缩略图的标识  $c='image'.$info['extension'];//生成输出缩略图的函数,不能分开写,否则报错  imagecopyresampled($mu1,$yuan,0,0,0,
0,$m120w,$m120h,$imagw,$imagh);//生成缩略图120  $res=$c($mu1,$xin.'/'.$image1);//存放缩略图  if(!$res){  alert('生成120缩略图失败');  exit;  }  imagecopyresampled($mu2,$yuan,0,0
,0,0,$m300w,$m300h,$imagw,$imagh);//php生成缩略图生成缩略图120  $res=$c($mu2,$xin.'/'.$image2);//存放缩略图  if($res){  alert('生成300缩略图成功');  exit;  }  }  }  $tpl->display(tu/tu.html);  ?> 
以上这一大段的代码示例就是php生成缩略图的相关实现方法。
http://www.bkjia.com/phpjc/446079.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/446079.htmltecharticle我们在运用 php生成缩略图html代码 !doctypehtmlpublic-//w3c//dtdhtml4.0transitional//en > html > head > title > 上传图片 /title > meta name = generator content =...
其它类似信息

推荐信息