欢迎光临
我们一直在努力

缩略图生成的php程序[转自奥索]-PHP教程,图像处理

建站超值云服务器,限时71元/月

客户端上载的页面:
——————–          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{print("不接受的图片!");exit;}
if(empty($image2)){print("系统错误,请重试");exit;}
$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");
?>

————————-     说明       ———————-
本代码特点在于将所有难看的warning转换为可以自已设计输出的出错提示,@作用在于抑制出借信息。此代码默认的是将图片转换为长宽不超过150像素的缩略图,并保存为new.gif  。使用时可以随意修改。
本代码由turtlevan( turtlevan@263.net )制作,您可以任意使用与修改,也可在网络上任意传播,但不得剽窃为已有。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 缩略图生成的php程序[转自奥索]-PHP教程,图像处理
分享到: 更多 (0)