缩略图生成的php程序
程序员文章站
2022-05-11 16:25:41
...
客户端上载的页面:
-------------------- upload.htm ---------------------
<form enctype="multipart/form-data"
method="post" action="upload.php">
<input type="hidden" name="MAX_FILE_SIZE" value="10240000000">请选择或输入上传文件名:<input name="upfile" type="file">
<input type="submit" value="开始上传">
--------------------- upload.php -------------------
<?
if(empty($upfile)){
print("No file was transfered!\n无文件上传!");
exit;
}
$image_path=$upfile;
@$image_info=getimagesize($image_path);
if($image_info[2]==2)
{@$image2=imagecreatefromjpeg($image_path);
}
else if($image_info[2]==1){
@$image2=imagecreatefromgif($image_path);
}
else
if(empty($image2))
$image2_x=imagesx($image2);
$image2_y=imagesy($image2);
if($image2_x==$image2_y){
$x=150;
$y=0;
}
else if($image2_x>$image2_y){
$x=150;
$y=intval(150*$image2_y/$image2_x);
}
else{
$y=150;
$x=intval(150*$image2_x/$image2_y);
}
$image1=imagecreate($x,$y);
imagecopyresized($image1,$image2,0,0,0,0,$x,$y,$image2_x,$image2_y);
imagegif($image1,"new.gif");
?>
-------------------- upload.htm ---------------------
<form enctype="multipart/form-data"
method="post" action="upload.php">
<input type="hidden" name="MAX_FILE_SIZE" value="10240000000">请选择或输入上传文件名:<input name="upfile" type="file">
<input type="submit" value="开始上传">
--------------------- upload.php -------------------
<?
if(empty($upfile)){
print("No file was transfered!\n无文件上传!");
exit;
}
$image_path=$upfile;
@$image_info=getimagesize($image_path);
if($image_info[2]==2)
{@$image2=imagecreatefromjpeg($image_path);
}
else if($image_info[2]==1){
@$image2=imagecreatefromgif($image_path);
}
else
if(empty($image2))
$image2_x=imagesx($image2);
$image2_y=imagesy($image2);
if($image2_x==$image2_y){
$x=150;
$y=0;
}
else if($image2_x>$image2_y){
$x=150;
$y=intval(150*$image2_y/$image2_x);
}
else{
$y=150;
$x=intval(150*$image2_x/$image2_y);
}
$image1=imagecreate($x,$y);
imagecopyresized($image1,$image2,0,0,0,0,$x,$y,$image2_x,$image2_y);
imagegif($image1,"new.gif");
?>
上一篇: 浅谈JavaScript Date日期和时间对象_基础知识
下一篇: 数据库事务介绍