dever 6 years ago
parent
commit
edb5362ab5
4 changed files with 518 additions and 101 deletions
  1. 3 3
      database/upload.php
  2. 145 42
      src/Lib/Img.php
  3. 243 56
      src/Store/Core.php
  4. 127 0
      src/View.php

+ 3 - 3
database/upload.php

@@ -85,7 +85,7 @@ return array
 		
 		'type'		=> array
 		(
-			'type' 		=> 'varchar-255',
+			'type' 		=> 'varchar-800',
 			'name' 		=> '限制文件后缀类型-多个用逗号隔开',
 			'default' 	=> '',
 			'desc' 		=> '请输入限制文件类型',
@@ -146,8 +146,8 @@ return array
 		(
 			'"默认图片配置",1,"jpg,png,gif",1,' . time(),
 			'"默认音频配置",1,"mp3",1,' . time(),
-			'"默认视频配置",1,"mp4",1,' . time(),
-			'"默认文件配置",1,"jpg,png,gif,doc,pdf,rar,zip,xls,xlsx,docx",1,' . time(),
+			'"默认视频配置",1,"video",1,' . time(),
+			'"默认文件配置",1,"jpg,png,gif,doc,pdf,rar,zip,xls,xlsx,docx,msi",1,' . time(),
 		),
 	),
 	

+ 145 - 42
src/Lib/Img.php

@@ -189,6 +189,9 @@ class Img
      */
     public function setSource($source)
     {
+        if (!$source) {
+            return $this;
+        }
         $this->_source = $source;
         $this->_check('source');
         $this->_image();
@@ -217,7 +220,8 @@ class Img
      */
     public function getDest($key = false)
     {
-        return ($key && isset($this->_dest[$key])) ? $this->_dest[$key] : $this->_desc;
+        $this->_destroy();
+        return ($key && isset($this->_dest[$key])) ? $this->_dest[$key] : $this->_dest;
     }
     
     /**
@@ -276,16 +280,20 @@ class Img
      * @desc 批量建立
      * @param *
      */
-    public function init($config)
+    public function init($source, $config, $setup = false, $name = false)
     {
-        $this->setSource($config['source']);
-        if (isset($config['setup']) && $config['setup'] == true) {
-            $this->setSource($config['setup']);
+        if ($setup == true) {
+            $this->setSetup($setup);
         }
-        unset($config['source']);
+        $this->setSource($source);
+        if ($name) $this->setName($name);
         foreach ($config as $k => $v) {
-            $this->$k($config['source'], $v);
+            $k = $v['method'];
+            $m = 'set' . ucfirst($k);
+            $this->$m($v);
+            $this->loadMethod($k);
         }
+        $this->_name = false;
         return $this->getDest();
     }
 
@@ -417,15 +425,18 @@ class Img
     private function _image()
     {
         $this->_check('source');
-        switch ($this->_type) {
-            case 'gd' :
-                $this->_image = $this->_gd_get($this->_source);
-                break;
-            case 'im' :
-                $this->_image = new \Imagick($this->_source);
-                $this->_imageType = strtolower($this->_image->getImageFormat());
-                break;
+        if (!$this->_image) {
+            switch ($this->_type) {
+                case 'gd' :
+                    $this->_image = $this->_gd_get($this->_source);
+                    break;
+                case 'im' :
+                    $this->_image = new \Imagick($this->_source);
+                    $this->_imageType = strtolower($this->_image->getImageFormat());
+                    break;
+            }
         }
+        
         return $this->_image;
     }
     
@@ -446,27 +457,31 @@ class Img
         $this->_dest['mark'] = $this->getName('_mark.jpg');
 
         if ($this->_setup == true || !file_exists($this->_dest['mark'])) {
-            $water  = $this->_gd_get($this->_mark['water']);
+            if (isset($this->_mark['radius'])) {
+                $water = $this->_gd_radius($this->_mark['water'], $this->_mark['radius']);
+            } else {
+                $water  = $this->_gd_get($this->_mark['water']);
+            }
+
             $source_x = imagesx($this->_image);
             $source_y = imagesy($this->_image);
-            $water_x = imagesx($water);
-            $water_y = imagesy($water);
+            $water_x    = isset($this->_mark['width']) ? $this->_mark['width'] : imagesx($water);
+            $water_y    = isset($this->_mark['height']) ? $this->_mark['height'] : imagesy($water);
+
             $xy      = $this->_get_mark($source_x, $source_y, $water_x, $water_y);
 
             if ($xy[2] == false) {
-                $this->_gd_destroy($this->_image);
                 $this->_gd_destroy($water);
                 return;
             }
 
-            $im = $this->_gd_copy($water, $water_x, $water_y, 0, 0, $l, $t, $this->_image);
+            //$water = $this->_gd_copy($water, $water_x, $water_y, 0, 0, 0, 0, false);
+            $im = $this->_gd_copy($water, $water_x, $water_y, 0, 0, $xy[0], $xy[1], $this->_image);
 
             imagejpeg($im, $this->_dest['mark']);
 
-            $this->_gd_destroy($this->_image);
             $this->_gd_destroy($water);
         }
-        $this->_image = false;
     }
 
     /**
@@ -583,9 +598,6 @@ class Img
                 $this->_gd_destroy($im);
             }
         }
-
-        $this->_gd_destroy($this->_image);
-        $this->_image = false;
     }
 
     /**
@@ -647,8 +659,6 @@ class Img
                 $this->_gd_destroy($im);
             }
         }
-        $this->_gd_destroy($this->_image);
-        $this->_image = false;
     }
     
     /**
@@ -686,9 +696,7 @@ class Img
             }
 
             imagejpeg($this->_image, $this->_dest['txt']);
-            $this->_gd_destroy($this->_image);
         }
-        $this->_image = false;
     }
 
     /**
@@ -918,8 +926,6 @@ class Img
         }
         
         $this->_name = false;
-
-        //$this->_image = false;
     }
     /**
      * @desc 建立原图压缩图
@@ -941,8 +947,6 @@ class Img
     		$this->_image->setImageCompressionQuality($this->_quality);
     		$this->_image->writeImage($this->_dest['compress']);
         }
-
-        $this->_image = false;
 	}
     
     /**
@@ -1057,8 +1061,6 @@ class Img
 				}
             }
         }
-
-        $this->_image = false;
     }
 
     private function _im_gif($w, $h, $x, $y, $d = false, $num = false)
@@ -1110,13 +1112,17 @@ class Img
         $this->_dest['mark'] = $this->getName('_mark.jpg');
 
         if ($this->_setup == true || !file_exists($this->_dest['mark'])) {
-            $water = new \Imagick($this->_mark['water']);
+            if (isset($this->_mark['radius'])) {
+                $water = $this->_im_radius($this->_mark['water'], $this->_mark['radius']);
+            } else {
+                $water = new \Imagick($this->_mark['water']);
+            }
             $draw = new \ImagickDraw();
 
             $source_x   = $this->_image->getImageWidth();
             $source_y   = $this->_image->getImageHeight();
-            $water_x    = $water->getImageWidth();
-            $water_y    = $water->getImageHeight();
+            $water_x    = isset($this->_mark['width']) ? $this->_mark['width'] : $water->getImageWidth();
+            $water_y    = isset($this->_mark['height']) ? $this->_mark['height'] : $water->getImageHeight();
             $xy         = $this->_get_mark($source_x, $source_y, $water_x, $water_y);
 
 
@@ -1130,8 +1136,6 @@ class Img
 	
             $this->_image->writeImage($this->_dest['mark']);
         }
-
-        $this->_image = false;
     }
 
     /**
@@ -1172,8 +1176,90 @@ class Img
 
             $this->_image->writeImage($this->_dest['txt']);
         }
+    }
 
-        $this->_image = false;
+    /**
+     * @desc 圆角图片
+     * @param *
+     */
+    private function _im_radius($img = '', $radius = -1)
+    {
+        $image = new \Imagick($img);
+        $image->setImageFormat('png');
+        if ($radius == -1) {
+            $x = $image->getImageWidth() / 2;
+            $y = $image->getImageHeight() / 2;
+        } else {
+            $x = $image->getImageWidth() - $radius;
+            $y = $image->getImageHeight() - $radius;
+        }
+        $image->roundCorners($x, $y);
+        return $image;
+    }
+
+    /**
+     * @desc 圆角图片
+     * @param *
+     */
+    private function _gd_radius($imgpath = '', $radius = 0)
+    {
+        $ext     = pathinfo($imgpath);
+        $src_img = null;
+        switch ($ext['extension']) {
+        case 'jpg':
+            $src_img = imagecreatefromjpeg($imgpath);
+            break;
+        case 'png':
+            $src_img = imagecreatefrompng($imgpath);
+            break;
+        }
+        $wh = getimagesize($imgpath);
+        $w  = $wh[0];
+        $h  = $wh[1];
+        $radius = $radius <= 0 ? (min($w, $h) / 2) : $radius;
+        $img = imagecreatetruecolor($w, $h);
+        //这一句一定要有
+        imagesavealpha($img, true);
+        //拾取一个完全透明的颜色,最后一个参数127为全透明
+        $bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
+        imagefill($img, 0, 0, $bg);
+        $r = $radius; //圆 角半径
+        for ($x = 0; $x < $w; $x++) {
+            for ($y = 0; $y < $h; $y++) {
+                $rgbColor = imagecolorat($src_img, $x, $y);
+                if (($x >= $radius && $x <= ($w - $radius)) || ($y >= $radius && $y <= ($h - $radius))) {
+                    //不在四角的范围内,直接画
+                    imagesetpixel($img, $x, $y, $rgbColor);
+                } else {
+                    //在四角的范围内选择画
+                    //上左
+                    $y_x = $r; //圆心X坐标
+                    $y_y = $r; //圆心Y坐标
+                    if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
+                        imagesetpixel($img, $x, $y, $rgbColor);
+                    }
+                    //上右
+                    $y_x = $w - $r; //圆心X坐标
+                    $y_y = $r; //圆心Y坐标
+                    if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
+                        imagesetpixel($img, $x, $y, $rgbColor);
+                    }
+                    //下左
+                    $y_x = $r; //圆心X坐标
+                    $y_y = $h - $r; //圆心Y坐标
+                    if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
+                        imagesetpixel($img, $x, $y, $rgbColor);
+                    }
+                    //下右
+                    $y_x = $w - $r; //圆心X坐标
+                    $y_y = $h - $r; //圆心Y坐标
+                    if (((($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y)) <= ($r * $r))) {
+                        imagesetpixel($img, $x, $y, $rgbColor);
+                    }
+                }
+            }
+        }
+        return $img;
     }
 
     private function _get_mark($source_x, $source_y, $water_x, $water_y)
@@ -1182,7 +1268,11 @@ class Img
         $l = 0;
         $t = 0;
         $state = true;
-        if ($this->_mark['position']) {
+
+        if ($this->_mark['position'] && is_array($this->_mark['position'])) {
+            $l = $this->_mark['position'][0];
+            $t = $this->_mark['position'][1];
+        } elseif ($this->_mark['position']) {
             switch ($this->_mark['position']) {
                 case 1:
                     //左上
@@ -1245,4 +1335,17 @@ class Img
 		}
 		return $file;
 	}
+
+    /**
+     * @desc 销毁资源
+     * @param *
+     */
+    private function _destroy()
+    {
+        if ($this->_type == 'gd') {
+            imagedestroy($this->_image);
+        }
+        
+        $this->_image = false;
+    }
 }

+ 243 - 56
src/Store/Core.php

@@ -32,20 +32,20 @@ class Core
 	protected $base = '';
 	
 	/**
-     * __construct
-     * 
-     * @return mixed
-     */
+	 * __construct
+	 * 
+	 * @return mixed
+	 */
 	public function __construct($data = array())
 	{
 		$this->data = $data;
 	}
 
 	/**
-     * 获取根目录
-     * 
-     * @return mixed
-     */
+	 * 获取根目录
+	 * 
+	 * @return mixed
+	 */
 	protected function root()
 	{
 		if (!$this->base) {
@@ -57,10 +57,10 @@ class Core
 	}
 	
 	/**
-     * 验证数据
-     * 
-     * @return mixed
-     */
+	 * 验证数据
+	 * 
+	 * @return mixed
+	 */
 	private function check($param)
 	{
 		foreach ($param as $k => $v) {
@@ -74,10 +74,10 @@ class Core
 	}
 	
 	/**
-     * 验证key是否包含有后续处理的方法
-     * 
-     * @return mixed
-     */
+	 * 验证key是否包含有后续处理的方法
+	 * 
+	 * @return mixed
+	 */
 	private function check_handle()
 	{
 		if (isset($this->data['key']) && strpos($this->data['key'], '_') !== false) {
@@ -91,10 +91,10 @@ class Core
 	}
 	
 	/**
-     * 验证文件是否存在
-     * 
-     * @return mixed
-     */
+	 * 验证文件是否存在
+	 * 
+	 * @return mixed
+	 */
 	private function check_file()
 	{
 		if ($this->data['file']['tmp_name'] == '') {
@@ -104,10 +104,10 @@ class Core
 	}
 	
 	/**
-     * 验证基本配置
-     * 
-     * @return mixed
-     */
+	 * 验证基本配置
+	 * 
+	 * @return mixed
+	 */
 	private function check_key()
 	{
 		if (trim($this->data['key']) == '') {
@@ -124,10 +124,10 @@ class Core
 	}
 	
 	/**
-     * 验证文件类型
-     * 
-     * @return mixed
-     */
+	 * 验证文件类型
+	 * 
+	 * @return mixed
+	 */
 	private function check_type()
 	{
 		$ext = $this->getExt($this->data['file']['tmp_name']);
@@ -140,10 +140,10 @@ class Core
 	}
 	
 	/**
-     * 验证文件大小
-     * 
-     * @return mixed
-     */
+	 * 验证文件大小
+	 * 
+	 * @return mixed
+	 */
 	private function check_size()
 	{
 		if ($this->config['width'] > 0 || $this->config['height'] > 0) {
@@ -168,10 +168,10 @@ class Core
 	}
 	
 	/**
-     * 上传操作
-     * 
-     * @return mixed
-     */
+	 * 上传操作
+	 * 
+	 * @return mixed
+	 */
 	public function copy()
 	{
 		$this->output['status'] = 1; 
@@ -280,13 +280,196 @@ class Core
 
 		Dever::load('upload/file-insert', $param);
 	}
-	
+
 	/**
-     * getExt
-     * 
-     * @return mixed
-     */
+	 * getExt
+	 * 
+	 * @return mixed
+	 */
 	protected function getExt($filename)
+	{
+		if (!function_exists('finfo_open')) {
+			return $this->getExtByByte($filename);
+		}
+		$finfo = finfo_open(FILEINFO_MIME); // 返回 mime 类型
+		$code = finfo_file($finfo, $filename);
+		finfo_close($finfo);
+		$temp = explode(';', $code);
+		$ext = $this->getExtByMine($temp[0]);
+		if (!$ext || $ext == 'txt') {
+			$ext = $this->getExtByByte($filename);
+		}
+
+		return $ext;
+	}
+
+	/**
+	 * 根据mime类型获取文件扩展名
+	 * 
+	 * @return mixed
+	 */
+	protected function getExtByMine($mine)
+	{
+		$mine = trim($mine);
+		$config = array
+		(
+			'application/envoy' => 'evy',
+			'application/fractals' => 'fif',
+			'application/futuresplash' => 'spl',
+			'application/hta' => 'hta',
+			'application/internet-property-stream' => 'acx',
+			'application/mac-binhex40' => 'hqx',
+			'application/msword' => 'doc',
+			'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
+			'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
+			'video/x-m4v' => 'mp4',
+			'application/octet-stream' => 'exe',
+			'application/oda' => 'oda',
+			'application/olescript' => 'axs',
+			'application/pdf' => 'pdf',
+			'application/pics-rules' => 'prf',
+			'application/pkcs10' => 'p10',
+			'application/pkix-crl' => 'crl',
+			'application/postscript' => 'ai',
+			'application/postscript' => 'eps',
+			'application/postscript' => 'ps',
+			'application/rtf' => 'rtf',
+			'application/set-payment-initiation' => 'setpay',
+			'application/set-registration-initiation' => 'setreg',
+			'application/vnd.ms-excel' => 'xls',
+			'application/vnd.ms-outlook' => 'msg',
+			'application/vnd.ms-pkicertstore' => 'sst',
+			'application/vnd.ms-pkiseccat' => 'cat',
+			'application/vnd.ms-pkistl' => 'stl',
+			'application/vnd.ms-powerpoint' => 'ppt',
+			'application/vnd.ms-project' => 'mpp',
+			'application/vnd.ms-works' => 'wps',
+			'application/winhlp' => 'hlp',
+			'application/x-bcpio' => 'bcpio',
+			'application/x-cdf' => 'cdf',
+			'application/x-compress' => 'z',
+			'application/x-compressed' => 'tgz',
+			'application/x-cpio' => 'cpio',
+			'application/x-csh' => 'csh',
+			'application/x-director' => 'dir',
+			'application/x-dvi' => 'dvi',
+			'application/x-gtar' => 'gtar',
+			'application/x-gzip' => 'gz',
+			'application/x-hdf' => 'hdf',
+			'application/x-internet-signup' => 'isp',
+			'application/x-iphone' => 'iii',
+			'application/x-javascript' => 'js',
+			'application/x-latex' => 'latex',
+			'application/x-msaccess' => 'mdb',
+			'application/x-mscardfile' => 'crd',
+			'application/x-msclip' => 'clp',
+			'application/x-msdownload' => 'dll',
+			'application/x-msmediaview' => 'mvb',
+			'application/x-msmetafile' => 'wmf',
+			'application/x-msmoney' => 'mny',
+			'application/x-mspublisher' => 'pub',
+			'application/x-msschedule' => 'scd',
+			'application/x-msterminal' => 'trm',
+			'application/x-mswrite' => 'wri',
+			'application/x-netcdf' => 'cdf',
+			'application/x-netcdf' => 'nc',
+			'application/x-perfmon' => 'pma',
+			'application/x-pkcs12' => 'p12',
+			'application/x-pkcs12' => 'pfx',
+			'application/x-pkcs7-certificates' => 'p7b',
+			'application/x-pkcs7-certreqresp' => 'p7r',
+			'application/x-pkcs7-mime' => 'p7c',
+			'application/x-pkcs7-signature' => 'p7s',
+			'application/x-sh' => 'sh',
+			'application/x-shar' => 'shar',
+			'application/x-shockwave-flash' => 'swf',
+			'application/x-stuffit' => 'sit',
+			'application/x-sv4cpio' => 'sv4cpio',
+			'application/x-sv4crc' => 'sv4crc',
+			'application/x-tar' => 'tar',
+			'application/x-tcl' => 'tcl',
+			'application/x-tex' => 'tex',
+			'application/x-texinfo' => 'texi',
+			'application/x-texinfo' => 'texinfo',
+			'application/x-troff' => 'roff',
+			'application/x-troff' => 't',
+			'application/x-troff' => 'tr',
+			'application/x-troff-man' => 'man',
+			'application/x-troff-me' => 'me',
+			'application/x-troff-ms' => 'ms',
+			'application/x-ustar' => 'ustar',
+			'application/x-wais-source' => 'src',
+			'application/x-x509-ca-cert' => 'cer',
+			'application/ynd.ms-pkipko' => 'pko',
+			'application/zip' => 'zip',
+			'audio/basic' => 'au',
+			'audio/basic' => 'snd',
+			'audio/mid' => 'mid',
+			'audio/mid' => 'rmi',
+			'audio/mpeg' => 'mp3',
+			'audio/x-aiff' => 'aif',
+			'audio/x-aiff' => 'aifc',
+			'audio/x-aiff' => 'aiff',
+			'audio/x-mpegurl' => 'm3u',
+			'audio/x-pn-realaudio' => 'ram',
+			'audio/x-wav' => 'wav',
+			'image/bmp' => 'bmp',
+			'image/cis-cod' => 'cod',
+			'image/gif' => 'gif',
+			'image/ief' => 'ief',
+			'image/jpeg' => 'jpg',
+			'image/pipeg' => 'jfif',
+			'image/svg+xml' => 'svg',
+			'image/tiff' => 'tif',
+			'image/tiff' => 'tiff',
+			'image/x-cmu-raster' => 'ras',
+			'image/x-cmx' => 'cmx',
+			'image/x-icon' => 'ico',
+			'image/x-portable-anymap' => 'pnm',
+			'image/x-portable-bitmap' => 'pbm',
+			'image/x-portable-graymap' => 'pgm',
+			'image/x-portable-pixmap' => 'ppm',
+			'image/x-rgb' => 'rgb',
+			'image/x-xbitmap' => 'xbm',
+			'image/x-xpixmap' => 'xpm',
+			'image/x-xwindowdump' => 'xwd',
+			'message/rfc822' => 'mht',
+			'message/rfc822' => 'mhtml',
+			'message/rfc822' => 'nws',
+			'text/css' => 'css',
+			'text/h323' => '323',
+			'text/html' => 'html',
+			'text/iuls' => 'uls',
+			'text/plain' => 'txt',
+			'text/richtext' => 'rtx',
+			'text/scriptlet' => 'sct',
+			'text/tab-separated-values' => 'tsv',
+			'text/webviewhtml' => 'htt',
+			'text/x-component' => 'htc',
+			'text/x-setext' => 'etx',
+			'text/x-vcard' => 'vcf',
+			'video/mpeg' => 'mpeg',
+			'video/quicktime' => 'mov',
+			'video/x-ms-asf' => 'asx',
+			'video/x-msvideo' => 'avi',
+			'video/x-sgi-movie' => 'movie',
+			'x-world/x-vrml' => 'flr',
+			'application/x-rar' => 'rar',
+		);
+
+		if (isset($config[$mine])) {
+			return $config[$mine];
+		} else {
+			return false;
+		}
+	}
+	
+	/**
+	 * getExt 已废弃
+	 * 
+	 * @return mixed
+	 */
+	protected function getExtByByte($filename)
 	{
 		$file = fopen($filename,"rb");
 		$bin = fread($file,2);
@@ -297,50 +480,53 @@ class Core
 		switch ($typeCode) {
 			case 7790:
 				$fileType = 'exe';
-			break;
+				break;
 			case 7784:
 				$fileType = 'midi';
-			break;
+				break;
 			case 8297:
 				$fileType = 'rar';
-			break;
+				break;
 			case 255216:
 				$fileType = 'jpg';
-			break;
+				break;
 			case 7173:
 				$fileType = 'gif';
-			break;
+				break;
 			case 13780:
 				$fileType = 'png';
-			break;
+				break;
 			case 6677:
 				$fileType = 'bmp';
-			break;
+				break;
 			case 6787:
 				$fileType = 'swf';
-			break;
+				break;
 			case 6063;
 				$fileType = 'php|xml';
-			break;
+				break;
 			case 6033:
 				$fileType = 'html|htm|shtml';
-			break;
+				break;
 			case 8075:
 				$fileType = 'zip';
-			break;
+				break;
 			case 6782:
 			case 1310:
 				$fileType = 'txt';
-			break;
+				break;
 			case 4742:
 				$fileType = 'js';
-			break;
+				break;
 			case 8273:
 				$fileType = 'wav';
-			break;
+				break;
 			case 7368:
 				$fileType = 'mp3';
-			break;
+				break;
+			case 3780:
+				$fileType = 'pdf';
+				break;
 			default:
 				$fileType = 'unknown'.$typeCode;
 			break;
@@ -354,6 +540,7 @@ class Core
 		if ($strInfo['chars1'] == '-48' && $strInfo['chars2'] == '-49') {
 			return 'msi';
 		}
+
 		return $fileType;
 	}
 }

+ 127 - 0
src/View.php

@@ -8,6 +8,7 @@ namespace Upload\Src;
 
 use Dever;
 use Upload\Src\Store\Local as Handle;
+use Upload\Src\Lib\Img;
 
 class View
 {
@@ -45,4 +46,130 @@ class View
 
 		return $file;
 	}
+
+	/**
+     * create 生成图片
+     * @param array $config
+     * @param string $filename
+     *
+     * @return mixed
+     */
+	public function create($config = array(), $filename = '')
+	{
+		$this->img = isset($this->img) ? $this->img : new Img();
+
+		$mark = array
+		(
+			'method' => 'mark',
+			'water' => $config['image'][0]['url'],
+			'position' => array(100,200),
+			'width' => 100,
+			'height' => 100,
+			# 开启圆角
+			//'radius' => -1,
+		);
+
+		$send[] = $mark;
+
+		$mark = array
+		(
+			'method' => 'mark',
+			'water' => $config['image'][0]['url'],
+			'position' => array(200,500),
+			'width' => 100,
+			'height' => 100,
+			# 开启圆角
+			//'radius' => -1,
+		);
+		$send[] = $mark;
+
+		$name = $this->img->init($config['background'], $send, true, $config['background'] . '.jpg');
+		print_r($name);die;
+	}
+
+	public function creates($config = array(), $filename = '')
+	{
+		if(empty($filename)) header("content-type: image/png");
+        $imageDefault = array(
+            'left'=>0,
+            'top'=>0,
+            'right'=>0,
+            'bottom'=>0,
+            'width'=>100,
+            'height'=>100,
+            'opacity'=>100
+        );
+        $textDefault = array(
+            'text'=>'',
+            'left'=>0,
+            'top'=>0,
+            'fontSize'=>32,       //字号
+            'fontColor'=>'255,255,255', //字体颜色
+            'angle'=>0,
+        );
+        $background = $config['background'];//海报最底层得背景
+        //背景方法
+        $backgroundInfo = getimagesize($background);
+        $backgroundFun = 'imagecreatefrom'.image_type_to_extension($backgroundInfo[2], false);
+        $background = $backgroundFun($background);
+        $backgroundWidth = imagesx($background);  //背景宽度
+        $backgroundHeight = imagesy($background);  //背景高度
+        $imageRes = imageCreatetruecolor($backgroundWidth,$backgroundHeight);
+        $color = imagecolorallocate($imageRes, 0, 0, 0);
+        imagefill($imageRes, 0, 0, $color);
+        // imageColorTransparent($imageRes, $color);  //颜色透明
+        imagecopyresampled($imageRes,$background,0,0,0,0,imagesx($background),imagesy($background),imagesx($background),imagesy($background));
+        //处理了图片
+        if (!empty($config['image'])) {
+            foreach ($config['image'] as $key => $val) {
+                $val = array_merge($imageDefault,$val);
+                $info = getimagesize($val['url']);
+                $function = 'imagecreatefrom'.image_type_to_extension($info[2], false);
+                if ($val['stream']) {   //如果传的是字符串图像流
+                    $info = getimagesizefromstring($val['url']);
+                    $function = 'imagecreatefromstring';
+                }
+                if (isset($val['radius']) && $val['radius']) {
+                	$res = $this->radius($val['url'], $val['radius']);
+                } else {
+                	$res = $function($val['url']);
+                }
+                
+                $resWidth = $info[0];
+                $resHeight = $info[1];
+                //建立画板 ,缩放图片至指定尺寸
+                $canvas = imagecreatetruecolor($val['width'], $val['height']);
+                $color   = imagecolorallocate($background, 202, 201, 201); // 为真彩色画布创建白色背景,再设置为透明    
+			    imagefill($canvas, 0, 0, $color);
+			    imageColorTransparent($canvas, $color);
+                //关键函数,参数(目标资源,源,目标资源的开始坐标x,y, 源资源的开始坐标x,y,目标资源的宽高w,h,源资源的宽高w,h)
+                imagecopyresampled($canvas, $res, 0, 0, 0, 0, $val['width'], $val['height'],$resWidth,$resHeight);
+                $val['left'] = $val['left']<0?$backgroundWidth- abs($val['left']) - $val['width']:$val['left'];
+                $val['top'] = $val['top']<0?$backgroundHeight- abs($val['top']) - $val['height']:$val['top'];
+                //放置图像
+                imagecopymerge($imageRes,$canvas, $val['left'],$val['top'],$val['right'],$val['bottom'],$val['width'],$val['height'],$val['opacity']);//左,上,右,下,宽度,高度,透明度
+            }
+        }
+        # 处理文字
+        if (!empty($config['text'])) {
+            foreach ($config['text'] as $key => $val) {
+                $val = array_merge($textDefault,$val);
+                list($R,$G,$B) = explode(',', $val['fontColor']);
+                $fontColor = imagecolorallocate($imageRes, $R, $G, $B);
+                $val['left'] = $val['left']<0?$backgroundWidth- abs($val['left']):$val['left'];
+                $val['top'] = $val['top']<0?$backgroundHeight- abs($val['top']):$val['top'];
+                imagettftext($imageRes,$val['fontSize'],$val['angle'],$val['left'],$val['top'],$fontColor,$val['fontPath'],$val['text']);
+            }
+        }
+        # 生成图片
+        if (!empty($filename)) {
+            $res = imagepng ($imageRes,$filename,9);
+            imagedestroy($imageRes);
+            if(!$res) return false;
+            return $filename;
+        } else {
+            imagepng ($imageRes, null, 9);
+            imagedestroy($imageRes);
+        }
+	}
 }