dever 6 years ago
parent
commit
c256562437
3 changed files with 60 additions and 27 deletions
  1. 6 0
      database/pic_crop.php
  2. 16 5
      src/Store/Local.php
  3. 38 22
      src/View.php

+ 6 - 0
database/pic_crop.php

@@ -10,6 +10,12 @@ $option = array
 	2 => '关闭',
 	2 => '关闭',
 );
 );
 
 
+$type = array
+(
+	1 => '居中裁剪',
+);
+
+
 return array
 return array
 (
 (
 	# 表名
 	# 表名

+ 16 - 5
src/Store/Local.php

@@ -150,17 +150,28 @@ class Local extends Core implements Config
      * 
      * 
      * @return mixed
      * @return mixed
      */
      */
-	public function handle_c($id)
+	public function handle_c($id, $source = false, $dest = false)
 	{
 	{
 		$config = Dever::load('upload/pic_crop-one', $id);
 		$config = Dever::load('upload/pic_crop-one', $id);
 		
 		
 		if ($config) {
 		if ($config) {
-			$this->name .= '_c' . $id;
+
+			if (!$source) {
+				$source = $this->output['file'];
+			}
+
+			if (!$dest) {
+				if (strpos($this->name, '_c') !== false) {
+					$temp = explode('_c', $this->name);
+					$this->name = $temp[0];
+				}
+				$this->name .= '_c' . $id;
+				$dest = $this->file();
+			}
 			
 			
 			$size = $config['width'] . '_' . $config['height'] . '_2';
 			$size = $config['width'] . '_' . $config['height'] . '_2';
-			
-			//false position
-            $this->img()->crop($this->output['file'], $size, false, true, $this->file());
+
+            $this->img()->crop($source, $size, false, true, $dest);
 		}
 		}
 	}
 	}
 }
 }

+ 38 - 22
src/View.php

@@ -15,38 +15,54 @@ class View
 	# 根据配置生成缩略图 暂时支持缩略图
 	# 根据配置生成缩略图 暂时支持缩略图
 	public function get($file)
 	public function get($file)
 	{
 	{
-		if (strstr($file, '_t')) {
-			$host = Dever::config('host')->uploadRes;
-			$root = Dever::data() . 'upload/';
-			$dest = str_replace($host, $root, $file);
+        $array = $this->getFile($file);
+        $source = $array[0];
+        $type = $array[1];
+        $id = $array[2];
 
 
-			if (!strstr($dest, 'http://') && !is_file($dest)) {
-				$temp = explode('_t', $dest);
-				$temp1 = explode('.', $temp[1]);
-				$id = $temp1[0];
-				$source = $temp[0] . '.' . $temp1[1];
+        if ($id > 0) {
+            $host = Dever::config('host')->uploadRes;
+            $root = Dever::data() . 'upload/';
+            $dest = str_replace($host, $root, $file);
 
 
-				$handle = new Handle();
-
-				$handle->handle_t($id, $source, $dest);
-			}
-		}
+            if (!strstr($dest, 'http://') && !is_file($dest)) {
+                $handle = new Handle();
+                $method = 'handle_' . $type;
+                $handle->$method($id, $source, $dest);
+            }
+        }
 
 
 		return $file;
 		return $file;
 	}
 	}
 
 
 	public function source($file)
 	public function source($file)
 	{
 	{
-		# 查看原图
-		if (strstr($file, '_t')) {
-			$temp = explode('_t', $file);
-			$temp1 = explode('.', $temp[1]);
-			$file = $temp[0] . '.' . $temp1[1];
-		}
-
-		return $file;
+		# 搜索文件信息
+        $array = $this->getFile($file);
+		return $array[0];
 	}
 	}
 
 
+    private function getFile($file)
+    {
+        $type = $id = false;
+
+        if (strstr($file, '_c')) {
+            $array = explode('_c', $file);
+            $type = 'c';
+        } elseif (strstr($file, '_t')) {
+            $array = explode('_t', $file);
+            $type = 't';
+        }
+
+        if (isset($array)) {
+            $temp = explode('.', $array[1]);
+            $id = $temp[0];
+            $file = $array[0] . '.' . $temp[1];
+        }
+
+        return array($file, $type, $id);
+    }
+
 	/**
 	/**
      * create 生成图片
      * create 生成图片
      * @param array $config
      * @param array $config