现在写东西都喜欢封装成类.....大家调用一下就行了..我就不说怎么调用了
复制代码 代码如下:<?php
class resize_image{
private $o_img_width;//原图像宽度
private $o_img_height;//原图像高度
private $n_img_width;//新图像宽度
private $n_img_height;//新图像高度
private $o_img_file;//原图像文件
private $o_img_source;//原图像资源
private $n_img_file;//新图像资源
private $n_img_source;//新图像资源
private $o_to_n_per=0.5;//图像缩放比
//初始化内部变量
function __construct($oldfile,$newfile){
list($width,$height)=getimagesize($oldfile);
$this->o_img_file=$oldfile;
$this->o_img_width=$width;
$this->o_img_height=$height;
$this->n_img_file=$newfile;
}
//等比例缩放并且解决GIF透明色为黑色背景的问题
function get_resize_scaling_img(){
$this->n_img_width=$this->o_img_width*$this->o_to_n_per;
$this->n_img_height=$this->o_img_height*$this->o_to_n_per;
//等比例缩放图片(算法)
if ( $this->n_img_width && ( $this->o_img_width <$this->o_img_height))
{
$this->n_img_width = ( $this->n_img_height/$this->o_img_height) * $this->o_img_width;
}
else
{
$this->n_img_height = ($this->n_img_width / $this->o_img_width) * $this->o_img_height;
}
$this->o_img_source=imagecreatefromgif($this->o_img_file);
//创建一个等比例缩放大小的画布
$this->n_img_source=imagecreatetruecolor($this->o_img_width,$this->n_img_height);
//美化:去除黑色不透明背景
$trans_init=imagecolortransparent($this->o_img_source);
//寻找透明色并且判断是否在总颜色中
if($trans_init>=0 && $trans_init < imagecolorstotal($this->o_img_source)){
//如果在的话则搜索这个颜色的RGB色相
$trans_index=imagecolorsforindex($this->o_img_source,$trans_init);
//找到之后就创建这样一个颜色
$trans_new=imagecolorallocate($this->n_img_source,$trans_index["red"],$trans_index["green"],$trans_index["blue"]);
//然后我们用这个颜色去填充新的图像
imagefill($this->n_img_source,0,0,$trans_new);
//然后我们在把填充色设置为透明
imagecolortransparent($this->n_img_source,$trans_new);
}
//拷贝原图像到新画板上
imagecopyresized($this->n_img_source,$this->o_img_source,0,0,0,0,$this->n_img_width,$this->n_img_height,$this->o_img_width,$this->o_img_height);
return $this->n_img_source;
}
//最终销毁资源
function __destruct(){
imagedestroy($this->o_img_source);
imagedestroy($this->n_img_source);
}
}
说明:因为先前没想那么多所以声明了很多私有的内部变量以便调用...程序看起来很笨拙啊......
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 华少翌.2005-华少翌【中唱艺能】【WAV+CUE】
- 群星《十二女声Ⅱ》[WAV/CUE/分轨][527MB]
- 大自然音乐系列《漫步在山裡》[WAV/CUE/分轨][502.8MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]
- 史依弘《史依弘交响乐京剧演唱专辑HQ》头版限量编号[WAV+CUE]
- 曼丽2020《女人三十风继续吹》HQCD[WAV+CUE]
- 曼丽2021《女人三十2雾之恋》HQCD[WAV+CUE]
- 隔壁老樊.2019-我曾【好听音乐】【FLAC分轨】
- 高林生.1993-牵挂你的人是我【白天鹅】【WAV+CUE】
- 洪卓立.2012-找个懂我的女孩(国专)【英皇娱乐】【WAV+CUE】
- 曼丽2022《女人三十3晚秋》HQCD[WAV+CUE]
- 曼丽2018《女人三十4冬天》HQCD[WAV+CUE]
- 柏菲-《好歌30年壹》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 大自然音乐系列《水舞》[WAV/CUE/分轨][424.3MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]