|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
根据功能来进行封装等。很多的不懂,在使用搜索引擎查找,或者请教老师和在老师详细的讲解、指导下,都能顺利解决。
<?php
classresizeimage{
//图片范例
var$type;
//实践宽度
var$width;
//实践高度
var$height;
//改动后的宽度
var$resize_width;
//改动后的高度
var$resize_height;
//是不是裁图
var$cut;
//源图像
var$srcimg;
//方针图像地点
var$dstimg;
//一时创立的图像
var$im;
functionresizeimage($img,$wid,$hei,$c,$dstpath){
$this->srcimg=$img;
$this->resize_width=$wid;
$this->resize_height=$hei;
$this->cut=$c;
//图片的范例
$this->type=strtolower(substr(strrchr($this->srcimg,"."),1));
//初始化图像
$this->initi_img();
//方针图像地点
$this->dst_img($dstpath);
$this->width=imagesx($this->im);
$this->height=imagesy($this->im);
//天生图像
$this->newimg();
ImageDestroy($this->im);
}
functionnewimg(){
//改动后的图像的比例
$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);
}
}
}
//初始化图像
functioniniti_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);
}
}
//图像方针地点
functiondst_img($dstpath){本文链接http://www.cxybl.com/html/wlbc/Php/20130326/37402.html从刚开始练习的PHP基础语法练习,到PHP语言在WEB中的应用,再到实际的项目开发,如留言版,相册系统,中小型公司网站系统,以及期间做过的有关团队合作的小游戏,让我受益匪浅,学到了很多。 |
|