그림 워터마크

2532 단어
<?php
header("content-type:text/html;charset=utf-8");
class Image{
    public $sourcePath;
    function __construct($sp){
        $this->sourcePath = $sp;
    }
    function GetImg(){
        $ext = strrpos($this->sourcePath, ".");
        $extName = strtolower(substr($this->sourcePath, $ext+1));// 
        $arr = getimagesize($this->sourcePath);
        // , 
        if($extName == "jpg"){
            $ic = "imagecreatefromjpeg";
        }elseif ($extName == "gif"){
            $ic = "imagecreatefromgif";
        }elseif ($extName == "png"){
            $ic = "imagecreatefrompng";
        }
        $img = $ic($this->sourcePath);
        $red = imagecolorallocate($img, 255, 255, 255);// 
        imagettftext($img,20,0,$arr[0]-90,$arr[1]-12,$red,"simhei.ttf","dreaman");
        // 【 , , , 】
        
        if($extName == "gif"){
            $ig = "imagegif";
        }elseif($extName == "png"){
            $ig = "imagepng";
        }elseif($extName == "jpg"){
            $ig = "imagejpeg";
        }
        $newFile = $ig($img,"1_tarena".".".$extName);
        return $newFile;
    }
    function getSmallImg($scale){
        //1.jpg --> 1_small.jpg  // a/b/1.jpg  1
        $srcPath = dirname($this->sourcePath)."/";
        //  (     )
        $srcName = basename($this->sourcePath);
        // ;
        $ext = explode(".",$srcName);
        // Array ( [0] => 1 [1] => jpg )
        // 
        $newFile = $srcPath.$ext[0]."_small".".".$ext[1];
        $sourceInfo = getimagesize($this->sourcePath);
        $src_width = $sourceInfo[0];
        $src_height = $sourceInfo[1];
        $dst_width = ceil($src_width*$scale);
        $dst_height = ceil($src_height*$scale);
        $dst_img = imagecreatetruecolor($dst_width,$dst_height);
        if($ext[1] == "jpg"){
            $ic = "imagecreatefromjpeg";
        }elseif ($ext[1] == "gif"){
            $ic = "imagecreatefromgif";
        }elseif ($ext[1] == "png"){
            $ic = "imagecreatefrompng";
        }
        $src_img = $ic($this->sourcePath);
        imagecopyresampled($dst_img,$src_img,0,0,0,0,$dst_width, $dst_height,$src_width,$src_height);
        imagejpeg($dst_img,$newFile);
        imagedestroy($dst_img);// 
        return     $newFile;
    }
}
?>

좋은 웹페이지 즐겨찾기