中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

PHP縮略圖類

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
define('ROOT','D:/Program Files/www/test/');
class Gd_Thumbnail_Tool{
protected static $image_w; //圖像的寬
protected static $image_h; //圖像的高
protected static $image_ext; //圖像的后綴
//縮略圖方法(參1要處理的圖,參2處理后的寬,參3處理后的高)
public static function mk_Thumb($image,$width=160,$height=160){
//對中文進行轉(zhuǎn)碼處理
$image=iconv('UTF-8','GB2312',$image);
//獲取圖片信息
self::image_Info($image);
//驗證是否獲取到信息
if( empty(self::$image_w) || empty(self::$image_h) || empty(self::$image_ext) ){return false;}
//判斷圖片的大小是否需要進行等比例縮略
if(self::$image_w<=$width && self::$image_h<=$height){$yes=false;}
$yes=true;
//按比例縮略
if($yes){
if( (self::$image_w<=self::$image_h) && (self::$image_h>$height) ){
//縮略后寬
$n=$height*(self::$image_w/self::$image_h);
$small_w=round($n);
//縮略后高
$small_h=$height;
}
if( (self::$image_w>=self::$image_h) && (self::$image_w>$width) ){
//縮略后寬
$small_w=$width;
//縮略后高
$n=$width*(self::$image_h/self::$image_w);
$small_h=round($n);
}
}
//以原圖做畫布
$a='imagecreatefrom'.self::$image_ext;
$original=$a($image);
//創(chuàng)建小畫布
$litter=imagecreatetruecolor($width,$height);
//把大圖縮略放入畫布
$x=($width-$small_w)/2;
$y=($height-$small_h)/2;
if(!$rs=imagecopyresampled($litter,$original,$x,$y,0,0,$small_w,$small_h,self::$image_w,self::$image_h)){return false;}
//保存路徑
$path=self::image_Dir().self::rand_Name().'.'.self::$image_ext;
//保存圖片
$keep='image'.self::$image_ext;
$keep($litter,$path);
//關(guān)閉圖片
imagedestroy($original);
imagedestroy($litter);
//返回路徑
return $path=strtr($path,array(ROOT=>''));
}
//獲取圖片信息方法
protected static function image_Info($image){
if($info=getimagesize($image)){
//圖像的寬
self::$image_w=$info[0];
//圖像的高
self::$image_h=$info[1];
//圖像的后綴
$ext=image_type_to_extension($info[2]);
$ext=ltrim($ext,'.');
self::$image_ext=$ext;
}
}
//生成路徑
protected static function image_Dir(){
$dir=ROOT.'Data/images/'.date('Y/m/d/',time());
if(!is_dir($dir)){mkdir($dir,0777,true);}
return $dir;
}
//隨機文件名
protected static function rand_Name(){
$name=str_shuffle('1234567890qwertyuiopasdfghjklmnbvcxz');
$name=substr($name,0,7);
return $name=$name.'_smal';
}
}
//測試
//echo Gd_Thumbnail_Tool::mk_Thumb('啊.jpg');
//返回效果:Data/images/2013/02/01/ei3ufpr_smal.jpeg
?>
 


標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:android的 Http工具類

下一篇:iOS使后臺可以運行代碼 比如定時器