[PHP5]T.T.R 缩略图/截图 生成类!

 


<? php
/**
 *TTR缩略图截图类
 *2007-09-23
 *[url]
http://www.Gx3.cn[/url]
 *QQ:252319874
 *类实例:$a = ResizeImage::getInstance();
 *创建方法:$a->create(string imagename,int resizewidth,int resizeheight,[boolen cutmode],[int cutX],[int cutY])
 *可选参数说明:
 *cutmode,默认false:创建缩略图,true:剪裁图片
 *cutX,cutY:要截取原图片的,xy坐标以左上角为原点
*
*/


class  ResizeImage
{
    
private $type=null;
    
private $width=0;
    
private $height=0;
    
private $resize_width=0;
    
private $resize_height=0;
    
private $cutX=0;
    
private $cutY=0;
    
private $cutmode=true;
    
private $imagepath=null;
    
private $savepath=null;
    
private $uploadpath="uploadfile/";
    
private $im;
    
static $instance=null;
    
private $resizeimge=null;
    
    
private function __construct()
    
{
        
    }

    
    
public function create($imagepath,$resizewidth,$resizeheight,$cutmode=false,$x=0,$y=0)
    
{
        $
this->imagepath=$imagepath;
        $
this->resize_width=$resizewidth;
        $
this->resize_height=$resizeheight;
        $
this->cutmode=$cutmode;
        $
this->cutX=$x;
        $
this->cutY=$y;
        $
this->type=$this->getImageType();
        $
this->initImage();
        $
this->getImageDstPath();
        $
this->width=$this->getImageX();
        $
this->height=$this->getImageY();
        $
this->createResizeImage();
    }

    
    
    
public static function getInstance()
    
{
        
if(self::$instance==null)
        
{
            self::$instance 
= new ResizeImage();
        }

        
return self::$instance;
    }

    
    
    
private function initImage()
    
{
        
switch($this->type)
        
{
            
case "jpg":
                $
this->im=imagecreatefromjpeg($this->imagepath);
                
break;
            
case "gif":
                $
this->im=imagecreatefromgif($this->imagepath);
                
break;
            
case "png":
                $
this->im=imagecreatefrompng($this->imagepath);
                
break;
        }

    }

    
    
private function getNewImageName()
    
{
        $arr
=explode("/",$this->imagepath);
        
if(count($arr)==0)
        
{
            $arr
=explode(".",$this->imagepath);
        }
else{
            $arr
=explode(".",$arr[count($arr)-1]);
        }

        
return $arr[0]."_s.jpg";
    }

    
    
private function createResizeImage()
    
{
        $resizerito
=($this->resize_width/$this->resize_height);
        $rito
=($this->width/$this->height);
        
        
if($this->cutmode)
        
{
            $reim
=imagecreatetruecolor($this->resize_width,$this->resize_height);
            imagecopyresampled($reim,$
this->im,0,0,$this->cutX,$this->cutY,$this->width,$this->height,$this->width,$this->height);
            imagejpeg($reim,$
this->savepath.$this->getNewImageName());
        }
else{
            
if($this->rito >= $this->resizerito)
            
{
                $reim
=imagecreatetruecolor($this->resize_width,$this->resize_width/$rito);
                imagecopyresampled($reim,$
this->im,0,0,0,0,$this->resize_width,($this->resize_width/$rito),$this->width,$this->height);
                imagejpeg($reim,$
this->savepath.$this->getNewImageName());
            }
else{
                $reim
=imagecreatetruecolor($this->resize_height*$rito,$this->resize_height);
                imagecopyresampled($reim,$
this->im,0,0,0,0,($this->resize_height*$rito),$this->resize_height,$this->width,$this->height);
                imagejpeg($reim,$
this->savepath.$this->getNewImageName());
            }

        }

    }

    
    
private function showErrorMessage($str)
    
{
        echo 
"<script>alert('$str')</script>";
    }

    
    
private function getImageX()
    
{
        
return imagesx($this->im);
    }

    
    
private function getImageY()
    
{
        
return imagesy($this->im);
    }

    
    
private function getImageType()
    
{
        
return strtolower(substr(strrchr($this->imagepath,"."),1));
    }

    
    
private function getImageDstPath()
    
{
        
if(substr($this->uploadpath,-1,1)!="/"
        
{
            $
this->savepath=$this->uploadpath."/".date("Ym");
        }
else{
            $
this->savepath=$this->uploadpath.date("Ym");
        }

        $
this->savepath=$this->getFolder($this->savepath);
    }

    
    
private function getFolder($folder)
    
{
        
if(!is_dir($folder))
        
{
            mkdir($folder);
        }

        
return $folder."/";
    }

    
    
public function __destruct()
    
{
        $
this->im=null;
        $
this->width=0;
        $
this->height=0;
        $
this->imagepath=null;
        $
this->savepath=null;
        $
this->resize_width=0;
        $
this->resize_height0;    
    }

}


?>

 

 

http://www.phpchina.com/bbs/thread-37195-1-1.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import numpy as np import matplotlib.pyplot as plt import sympy from scipy.interpolate import interp1d gamma = 1.2 R = 8.314 T0 = 500 Q = 50 * R * T0 a0 = np.sqrt(gamma * R * T0) M0 = 6.216 P_P0 = sympy.symbols('P_P0') num = 81 x0 = np.linspace(0,1,num) t_t0 = np.linspace(0,15,num) x = x0[1:] T_T0 = t_t0[1:] h0 = [] h1 = []#创建拉姆达为1的空数组 r = [] t = [] c = [] s = [] i = 0 for V_V0 in x: n1 = sympy.solve(1 / (gamma-1) * (P_P0 * V_V0 - 1) - 0.5 * (P_P0 + 1) * (1 - V_V0)- gamma * 0 * Q / a0 ** 2,P_P0)#lamuda=0的Hugoniot曲线方程 n2 = sympy.solve(1 / (gamma-1) * (P_P0 * V_V0 - 1) - 0.5 * (P_P0 + 1) * (1 - V_V0)- gamma * 1 * Q / a0 ** 2,P_P0)#lamuda=1的Hugoniot曲线方程 n3 = sympy.solve(-1 * P_P0 + 1 - gamma * M0 ** 2 * (V_V0 - 1),P_P0)#Reyleigh曲线方程 n4 = 12.014556 / V_V0#等温线 n5 = sympy.solve((P_P0 - 1 / (gamma+1) )* (V_V0-gamma / (gamma + 1)) - gamma / ((gamma + 1) ** 2),P_P0)#声速线 n6 = 10.6677 / np.power(V_V0,1.2)#等熵线 h0.append(n1) h1.append(n2) r.append(n3) t.append(n4) c.append(n5) s.append(n6) i = i+1 h0 = np.array(h0) h1 = np.array(h1) r = np.array(r) t = np.array(t) c = np.array(c) s = np.array(s) plt.plot(x,r,label='Rayleigh') plt.plot(x,t,color='purple',label='isothermal') plt.plot(x,s,color='skyblue',label='isentropic') a = np.where(h0 < 0) b = np.where(c < 0) h0 = np.delete(h0,np.where(h0 < 0)[0],axis = 0)#去除解小于0的值 h1 = np.delete(h1,np.where(h1 < 0)[0],axis = 0)#去除解小于0的值 c = np.delete(c,np.where(c < 0)[0],axis = 0)#去除解小于0的值 x0 = np.delete(x,a,axis = 0)#对应去除x轴上错误值的坐标 x1 = np.delete(x,b,axis = 0) plt.plot(x0,h0,label='Hugoniot(lambda=0)') plt.plot(x0,h1,label='Hugoniot(lambda=1)') plt.plot(x1,c,color='yellow',label='soniclocus') plt.ylim((0,50)) plt.legend() # 显示图例 plt.xlabel('V/V0') plt.ylabel('P/P0') f1 = interp1d(x1, c.T, kind='cubic') f2 = interp1d(x,r.T,kind='cubic') f3 = interp1d(x, t.T, kind='cubic') epsilon = 0.0001 x0 = 0.56 y0 = f1(x0) - f2(x0) while abs(y0) > epsilon: df = (f1(x0 + epsilon) - f2(x0 + epsilon) - y0) / epsilon x0 -= y0 / df y0 = f1(x0) - f2(x0) plt.scatter(x0, y0, 50, color ='red') plt.show()
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值