• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP图片操作类

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1,生成缩图

 

代码
<?php
///生成縮圖
//
/$resizeimage=new resizeimage($filesaved,$dstimg,250,250);
class resizeimage 

    
var $type
    
var $width
    
var $height
    
var $resize_width
    
var $resize_height
    
var $srcimg
    
var $dstimg
    
var $im;
    
var $desiredRatio;

    
function resizeimage($srcimg,$dstimg, $wid, $hei
    { 
        
$this->srcimg = $srcimg
        
$this->dstimg = $dstimg
        
//圖片的類型 
        $this->type = substr(strrchr($this->srcimg,"."),1); 
        
//初始化圖像 
        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);
            
        
//目標圖像寬和高
        $this->width = imagesx($this->im); 
        
$this->height = imagesy($this->im);
        
//計算縮圖的寬和高
        //若需要生產的縮圖的寬和高都大於源圖的寬高時都不需要縮小

        if( ($this->width<=$wid&& ($this->height<=$hei) ){
            
$this->resize_width=$this->width;
            
$this->resize_height=$this->height;
        }
else{
            
//若寬的縮小比例小於高的縮小比例時,則成生的縮圖的寬為$wid
            if( ($wid/$this->width) < ($hei/$this->height) ){
                
$this->desiredRatio=$wid/$this->width;
                
$this->resize_width=$wid;
                
$this->resize_height=(int)($this->height*$this->desiredRatio);
            
//若寬的縮小比例大於高的縮小比例時,則生成的縮圖的高為$hei
            }else{
                
$this->desiredRatio=$hei/$this->height;
                
$this->resize_height=$hei;
                
$this->resize_width=(int)($this->width*$this->desiredRatio);
            }
        }
        
//生成圖像
        $this->newimg(); 
        
//销毁一图像
        ImageDestroy ($this->im); 
    } 
    
function newimg() 
    { 
        
$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->height) ; 
        ImageJpeg (
$newimg,$this->dstimg); 
    }    

?>

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP回调函数的实现方法发布时间:2022-07-10
下一篇:
Php防跨站分析发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap