php代码
<?php 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){ //对中文进行转码处理 $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$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); //创建小画布 $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); //关闭图片 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 ?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Roblox: Grow A Garden - Complete Mutation Guide
4 weeks agoByDDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Clair Obscur: Expedition 33 - How To Get Perfect Chroma Catalysts
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
