谁传一个上传自动生成缩略图的代码上来啊? 听说PHP可以不用组件实现~ASP得装组件``所以我现在ASP的程序打算来采用一个PHP的上传头像代码~来实现可以生成头像缩略图~麻烦哪个高手能给个代码~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function resizeimage($img, $wid, $hei,$c,$type="s",$qianzhui) { $this->srcimg = $img; $this->resize_width = $wid; $this->resize_height = $hei; $this->cut = $c; $this->th_path = $qianzhui; //图片的类型 $this->type = substr(strrchr($this->srcimg,"."),1); //初始化图象 $this->initi_img(); //目标图象地址 $this -> dst_img($type); //-- $this->width = imagesx($this->im); $this->height = imagesy($this->im); //生成图象 $this->newimg(); ImageDestroy ($this->im); } function newimg() { //改变后的图象的比例 $resize_ratio = ($this->resize_width)/($this->resize_height); //实际图象的比例 $ratio = ($this->width)/($this->height); if(($this->cut)=="1") //裁图 { if($ratio>=$resize_ratio) //高度优先 { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height); ImageJpeg ($newimg,$this->dstimg); } if($ratio<$resize_ratio) //宽度优先 { $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio)); ImageJpeg ($newimg,$this->dstimg); } } else //不裁图 { if($ratio>=$resize_ratio) { $newimg = imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); } if($ratio<$resize_ratio) { $newimg = imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height); imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height)*$ratio, $this->resize_height, $this->width, $this->height); ImageJpeg ($newimg,$this->dstimg); } } } //初始化图象 function initi_img() { if($this->type=="jpg") { $this->im = imagecreatefromjpeg($this->srcimg); } if($this->type=="gif") { $this->im = imagecreatefromgif($this->srcimg); } if($this->type=="png") { $this->im = imagecreatefrompng($this->srcimg); } } //图象目标地址 function dst_img($type) { $name = $this->srcimg; $n=substr(strrchr($name,"/"),1); $this->dstimg = $this->th_path.$n.".".$type.".".$this->type; }} $resizeimage =new resizeimage($attachment,$w,$h,"1",$type,$qianzhui);这是使用方法 给你个简单的下载PHP Thumbnailer Class v2.0代码地址如下:http://www.gen-x-design.com/projects/php-thumbnailer-class/例子代码:include("class.Thumbnail.php");$tn_image = new Thumbnail("sample.jpg", 300, 300, 0);$tn_image->show(); $resizeimage =new resizeimage($attachment,$w,$h,"1",$type,$qianzhui);attachment表示上传后的图片地址,$w表示缩略图的宽,$h是缩略图的高,1表示裁图,$type表示缩略图后缀,如ss.sd.jpg,sd就是后缀,$qianzhui表示缩略图存放地址,这回总明白了饿 请问高手关于XML的问题 eclipse xdebug单步调试问题 PHP,如何在向一个网页POST提交数据后,得到返回的数据 求phpdesigner 的xdebug 能用浏览器调试的配置 ucenter的头像上传camera.swf,怎么让头像的长宽固定比例呢? session可以这样获取什么?不知道它是怎么写的 找人二次开发ecshop网站,有需求文档,劳务费可洽谈! 飞信机器人PHP版 调用接口 提供下载 有懂drupal的大神吗 thinkphp 根据无限极分类添加内容 小弟在线急求答案 跟写法 关于PHP MySQL连接错误 寻求创业合作者!限北京~
{
$this->srcimg = $img;
$this->resize_width = $wid;
$this->resize_height = $hei;
$this->cut = $c;
$this->th_path = $qianzhui;
//图片的类型
$this->type = substr(strrchr($this->srcimg,"."),1);
//初始化图象
$this->initi_img();
//目标图象地址
$this -> dst_img($type);
//--
$this->width = imagesx($this->im);
$this->height = imagesy($this->im);
//生成图象
$this->newimg();
ImageDestroy ($this->im);
}
function newimg()
{
//改变后的图象的比例
$resize_ratio = ($this->resize_width)/($this->resize_height);
//实际图象的比例
$ratio = ($this->width)/($this->height);
if(($this->cut)=="1")
//裁图
{
if($ratio>=$resize_ratio)
//高度优先
{
$newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height);
ImageJpeg ($newimg,$this->dstimg);
}
if($ratio<$resize_ratio)
//宽度优先
{
$newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, $this->resize_height, $this->width, (($this->width)/$resize_ratio));
ImageJpeg ($newimg,$this->dstimg);
}
}
else
//不裁图
{
if($ratio>=$resize_ratio)
{
$newimg = imagecreatetruecolor($this->resize_width,($this->resize_width)/$ratio);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, $this->resize_width, ($this->resize_width)/$ratio, $this->width, $this->height);
ImageJpeg ($newimg,$this->dstimg);
}
if($ratio<$resize_ratio)
{
$newimg = imagecreatetruecolor(($this->resize_height)*$ratio,$this->resize_height);
imagecopyresampled($newimg, $this->im, 0, 0, 0, 0, ($this->resize_height)*$ratio, $this->resize_height, $this->width, $this->height);
ImageJpeg ($newimg,$this->dstimg);
}
}
}
//初始化图象
function initi_img()
{
if($this->type=="jpg")
{
$this->im = imagecreatefromjpeg($this->srcimg);
}
if($this->type=="gif")
{
$this->im = imagecreatefromgif($this->srcimg);
}
if($this->type=="png")
{
$this->im = imagecreatefrompng($this->srcimg);
}
}
//图象目标地址
function dst_img($type)
{
$name = $this->srcimg;
$n=substr(strrchr($name,"/"),1);
$this->dstimg = $this->th_path.$n.".".$type.".".$this->type;
}
}
地址如下:
http://www.gen-x-design.com/projects/php-thumbnailer-class/例子代码:
include("class.Thumbnail.php");
$tn_image = new Thumbnail("sample.jpg", 300, 300, 0);
$tn_image->show();
attachment表示上传后的图片地址,$w表示缩略图的宽,$h是缩略图的高,1表示裁图,$type表示缩略图后缀,如ss.sd.jpg,sd就是后缀,$qianzhui表示缩略图存放地址,这回总明白了饿