分类分类
更新时间:2026-03-29 00:16:41作者:sa
jcrop+Uploadify+php无刷新头像上传,经过学习和研究做成的一个例子,共享出来以供大家参考和学习,有不合适的地方欢迎大家拍砖,至于jcrop和uploadify教程以后会逐渐整理出来

裁切图片类(注:例子中没用到,需要用的可以自己修改)
/**
* 裁切不同图片的一个类,大家可以看着用
*/
class cutImages{
private $filename; //原文件全路径
private $x; //横坐标
private $y; //纵坐标
private $x1; //源图宽
private $y1; //源图高
private $ext; //文件后缀
private $width=120; //宽
private $height=120; //高
private $jpeg_quality=90; //图片生成的保真度 范围0(质量最差)-100(质量最好)
public function __construct(){
}
/**
* 初始化截图对象
* @param unknown_type $filename
* @param unknown_type $x
* @param unknown_type $y
* @param unknown_type $x1
* @param unknown_type $y1
*/
public function initialize($filename,$x,$y,$x1,$y1){
if(file_exists($filename)){
$this->filename = $filename;
$pathinfo = pathinfo($filename);
$this->ext = strtolower($pathinfo['extension']); //将扩展名转为小写
}else{
$e = new Exception(‘the file is not exists!’,1050);
throw $e;
}
$this->x = $x;
$this->y = $y;
$this->x1 = $x1;
$this->y1 = $y1;
}
/**
* 生成截图
* 根据不同的图片格式生成不同的截图
*/
public function generateShot(){
switch($this->ext){
case ‘jpg’:
$this -> generateJpg();
break;
case ‘png’:
$this -> generatePng();
break;
case ‘gif’:
$this -> generateGif();
break;
default:
return false;
}
}
/**
* 获取生成的小图的文件
*/
public function getShotName(){
$pathinfo = pathinfo($this->filename);
$fileinfo = explode(‘.’,$pathinfo['basename']);
$cutfilename = $fileinfo[0].’_small’.$this->ext;
return $pathinfo['dirname'].’/’.$cutfilename;
}
/**
* 生成jpg图片
*/
public function generateJpg(){
$shotname = $this->getShotName();
$img_r = imagecreatefromjpeg($this->filename); //从url新建一图像
$dst_r = imageCreateTrueColor($this->width,$this->height); //创建一个真色源的图片
imagecopyresampled($dst_r,$img_r,0,0,$this->x,$this->y,$this->width,$this->height,$this->x1,$this->y1);
imagejpeg($dst_r,$shotname,$this->jpeg_quality);
return $shotname;
}
/**
* 生成png图片
*/
public function generatePng(){
$shotname = $this->getShotName();
$img_r = imagecreatefrompng($this->filename); //从url新建一图像
$dst_r = imageCreateTrueColor($this->width,$this->height); //创建一个真色源的图片
imagecopyresampled($dst_r,$img_r,0,0,$this->x,$this->y,$this->width,$this->height,$this->x1,$this->y1);
imagepng($dst_r,$shotname);
return $shotname;
}
/**
* 生成gif图片
*/
public function generateGif(){
$shotname = $this->getShotName();
$img_r = imagecreatefromgif($this->filename);
$dst_r = imageCreateTrueColor($this->width,$this->height);
imagecopyresampled($dst_r,$img_r,0,0,$this->x,$this->y,$this->width,$this->height,$this->x1,$this->y1);
if(imagegif($dst_r,$shotname)){
return $shotname;
}
}
}
下载:jcrop+Uploadify+php无刷新头像上传
相关
王道三国策略游戏380.18 MBv0.0.12026-03-28
下载刮个爽手机版休闲益智186.96 MBv1.0.282026-03-28
下载龙符天祭策略游戏756.03 Mv22026-03-28
下载入魂一番赏app网上购物106.66 Mv4.3.52026-03-28
下载童话师经营养成504.02 Mv1.1.52026-03-28
下载Bebo Cam app图像拍照264.51 Mv2.3.02026-03-28
下载纯三国官方正版策略游戏167.24 Mv0.0.12026-03-28
下载Poka Cam app图像拍照74.7 Mv1.8.02026-03-28
下载COLMO app趣味娱乐199.15 Mv2.3.5.22026-03-28
下载愤怒的小鸟变形金刚苹果版休闲游戏439.4 Mv2.39.02026-03-28
下载这也能切苹果版休闲游戏479.6 Mv21342026-03-28
下载口袋吉伊卡哇苹果手机版模拟游戏920.4 Mv2.0.02026-03-28
下载










