php 方便水印和缩略图的图形类

2019-04-10 10:47:39王旭

            if(!$args[2]) {
                $color = hexdec('7fffffff');
                imagecolortransparent($im,$color);
            }else {
                $color = hexdec(str_replace('#','',$args[2]));
            }
            $this->size = $this->size ? $this->size : array((int)$args[0] ,(int)$args[1]);
            imagefill($im, 1, 1, $color);
        }else {
            error("对不起,参数错误!");
        }
        //imagealphablending($im,false);//这两行用来记录透明通道
        imagesavealpha($im,true);
        imageinterlace($im,true);//开启隔行扫描
        return $im;
    }

    /*
    *生成缩略图
    *@param int $w 新图片的宽度
    *@param int $h 新图片的宽度
    *@param string/bool $color 可选,新图片的背景色,false或空为透明
    *@param bool $lashen 可选,是否拉伸,默认不拉伸
    */
    function suolue($w = null,$h = null,$color = false,$lashen = false) {
        $w_o = imagesx($this->im);
        $h_o = imagesy($this->im);
        if($w == null and $h != null) {
            $w = $h * $w_o/$h_o;
        }elseif ($w != null and $h == null){
            $h = $w * $h_o/$w_o;
        }
        $this->size = null;
        $im = $this->create($w,$h,$color);
        $w_n = $w;
        $h_n = $h;
        if($w_o/$h_o > $w/$h) {
            $h_n = $w*$h_o/$w_o;
相关文章 大家在看