|
现在写东西都喜欢封装成类.....大家调用一下就行了..我就不说怎么调用了
[U]复制代码[/U] 代码如下:
//初始化内部变量
function __construct($oldfile,$newfile){
list($width,$height)=getimagesize($oldfile);
$this->o_$oldfile;
$this->o_$width;
$this->o_$height;
$this->n_$newfile;
}
//等比例缩放并且解决GIF透明色为黑色背景的问题
function get_resize_scaling_img(){
$this->n_$this->o_*$this->o_to_n_per;
$this->n_$this->o_*$this->o_to_n_per;
//等比例缩放图片(算法)
if ( $this->n_( $this->o_))
{
$this->n_( $this->n_$this->o_) * $this->o_;
}
else
{
$this->n_($this->n_$this->o_) * $this->o_;
}
$this->o_($this->o_);
//创建一个等比例缩放大小的画布
$this->n_($this->o_,$this->n_);
//美化:去除黑色不透明背景
$trans_init=imagecolortransparent($this->o_);
//寻找透明色并且判断是否在总颜色中
if($trans_init>=0 && $trans_init o_)){
//如果在的话则搜索这个颜色的RGB色相
$trans_index=imagecolorsforindex($this->o_,$trans_init);
//找到之后就创建这样一个颜色
$trans_new=imagecolorallocate($this->n_,$trans_index["red"],$trans_index["green"],$trans_index["blue"]);
//然后我们用这个颜色去填充新的图像
imagefill($this->n_,0,0,$trans_new);
//然后我们在把填充色设置为透明
imagecolortransparent($this->n_,$trans_new);
}
//拷贝原图像到新画板上
imagecopyresized($this->n_,$this->o_,0,0,0,0,$this->n_,$this->n_,$this->o_,$this->o_);
return $this->n_;
}
//最终销毁资源
function __destruct(){
imagedestroy($this->o_);
imagedestroy($this->n_);
}
}
说明:因为先前没想那么多所以声明了很多私有的内部变量以便调用...程序看起来很笨拙啊......
您可能感兴趣的文章:完美实现GIF动画缩略图的php代码PHP支持多种格式图片上传(支持jpg、png、gif)PHP之生成GIF动画的实现方法PHP生成Gif图片验证码php调整gif动画图片尺寸示例代码分享PHP基于GD库的缩略图生成代码(支持jpg,gif,png格式)PHP使用GIFEncoder类生成的GIF动态图片验证码PHP使用GIFEncoder类生成gif动态滚动字幕PHP使用GIFEncoder类处理gif图片实例php判断GIF图片是否为动画的方法
|
|