dever 4 年 前
コミット
f03ec97b8b
8 ファイル変更85 行追加26 行削除
  1. 1 0
      database/file.php
  2. 19 1
      database/pic_crop.php
  3. 2 2
      database/pic_water.php
  4. 3 3
      database/upload.php
  5. 29 0
      lib/Store/Handle.php
  6. 2 2
      lib/Store/Local.php
  7. 19 12
      lib/Store/Qiniu.php
  8. 10 6
      src/View.php

+ 1 - 0
database/file.php

@@ -248,6 +248,7 @@ return array
 			'match' 	=> array('is_numeric', time()),
 			'desc' 		=> '',
 			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+			'order'		=> 'desc',
 		),
 	),
 

+ 19 - 1
database/pic_crop.php

@@ -12,7 +12,13 @@ $option = array
 
 $type = array
 (
-	1 => '居中裁剪',
+	1 => '左上',
+	2 => '左下',
+	3 => '右上',
+	4 => '右下',
+	5 => '居中',
+	6 => '上中',
+	7 => '下中',
 );
 
 
@@ -48,6 +54,18 @@ return array
 			'search'	=> 'fulltext',
 			'list'		=> true,
 		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'int-1',
+			'name' 		=> '裁剪位置',
+			'default' 	=> '1',
+			'desc' 		=> '裁剪位置',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $type,
+			'update'	=> 'select',
+			'list'		=> true,
+		),
 		
 		'width'		=> array
 		(

+ 2 - 2
database/pic_water.php

@@ -17,8 +17,8 @@ $water = array
 	3 => '右上',
 	4 => '右下',
 	5 => '居中',
-	6 => '左居中',
-	7 => '右居中',
+	6 => '中',
+	7 => '中',
 );
 
 return array

+ 3 - 3
database/upload.php

@@ -243,9 +243,9 @@ return array
 	(
 		'button' => array
 		(
-			'图片水印配置' => array('location', 'manage/project/database/list&project=upload&table=pic_water'),
-			'图片缩略配置' => array('location', 'manage/project/database/list&project=upload&table=pic_thumb'),
-			'图片裁剪配置' => array('location', 'manage/project/database/list&project=upload&table=pic_crop'),
+			'图片水印配置' => array('location', 'manage/project/database/list&project=upload&table=pic_water&oper_table=upload'),
+			'图片缩略配置' => array('location', 'manage/project/database/list&project=upload&table=pic_thumb&oper_table=upload'),
+			'图片裁剪配置' => array('location', 'manage/project/database/list&project=upload&table=pic_crop&oper_table=upload'),
 		),
 	),
 	

+ 29 - 0
lib/Store/Handle.php

@@ -13,6 +13,7 @@ class Handle
     public function __construct($data = array())
     {
         $this->yun = $this->local = false;
+
         $config = Dever::load('upload/lib/config')->get($data['key']);
         //$config = Dever::db('upload/upload')->one($data['key']);
         if (!$config) {
@@ -20,6 +21,11 @@ class Handle
             return;
         }
 
+        if (isset($data['yun']) && $data['yun']) {
+            $config['save_type'] = 4;
+            $config['yun'] = $data['yun'];
+        }
+
         $this->save_type = $config['save_type'];
 
         if ($this->save_type >= 2 && $config['yun']) {
@@ -116,4 +122,27 @@ class Handle
             return $yun;
         }
     }
+
+    public function handle_c($id, $source, $dest, $path)
+    {
+        $yun = $local = array();
+
+        if ($this->save_type <= 3) {
+            $local = $this->local->handle_c($id, $source, $dest);
+        }
+
+        if ($local) {
+            return $local;
+        }
+
+        if ($this->save_type >= 2) {
+            $yun = $this->yun->handle_c($id, $source, $dest, $path);
+        }
+
+        if ($this->save_type <= 2) {
+            return $local;
+        } elseif ($this->save_type > 2) {
+            return $yun;
+        }
+    }
 }

+ 2 - 2
lib/Store/Local.php

@@ -214,7 +214,7 @@ class Local extends Core implements Config
 	public function handle_c($id, $source = false, $dest = false)
 	{
 		$config = Dever::load('upload/pic_crop-one', $id);
-		
+
 		if ($config) {
 
 			if (!$source) {
@@ -232,7 +232,7 @@ class Local extends Core implements Config
 			
 			$size = $config['width'] . '_' . $config['height'] . '_2';
 
-            $this->img()->crop($source, $size, false, true, $dest);
+            $this->img()->crop($source, $size, $config['type'], true, $dest);
 		}
 
 		return $dest;

+ 19 - 12
lib/Store/Qiniu.php

@@ -159,7 +159,10 @@ class Qiniu extends Core implements Config
             }
 
             //?imageView2/2/w/360/h/270/format/png/q/75|imageslim
-            $dest = $this->data['host'] . $source . '?imageView2/2/w/'.$config['width'].'/h/'.$config['height'];
+            if (!strstr($source, 'http')) {
+                $source = $this->data['host'] . $source;
+            }
+            $dest = $source . '?imageView2/2/w/'.$config['width'].'/h/'.$config['height'];
 
             if (isset($config['compress']) && $config['compress'] > 0) {
                 $dest .= '/q/' . $config['compress'];
@@ -175,28 +178,32 @@ class Qiniu extends Core implements Config
      * 
      * @return mixed
      */
-    public function handle_c($id, $source = false, $dest = false)
+    public function handle_c($id, $source = false, $dest = false, $path = '')
     {
         $config = Dever::load('upload/pic_crop-one', $id);
-        
         if ($config) {
 
             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();
+            //?imageView2/2/w/360/h/270/format/png/q/75|imageslim
+            if (!strstr($source, 'http')) {
+                $source = $this->data['host'] . $source;
+            }
+            $temp = parse_url($source);
+            $file = ltrim($temp['path'], '/');
+            $file = Dever::db('upload/file')->one(array('file' => $file));
+
+            $x = $y = 0;
+            if ($file) {
+                list($x, $y) = $this->img()->get_position($file['width'], $file['height'], $config['width'], $config['height'], 'crop', $config['type']);
             }
             
-            $size = $config['width'] . '_' . $config['height'] . '_2';
+            $dest = $source . '?imageMogr2/crop/!'.$config['width'].'x'.$config['height'].'a'.$x.'a' . $y;
 
-            $this->img()->crop($source, $size, false, true, $dest);
+            $dest .= '|imageslim';
         }
+        return $dest;
     }
 }

+ 10 - 6
src/View.php

@@ -345,11 +345,11 @@ class View
         return false;
     }
 
-	# 根据配置生成缩略图 暂时支持缩略
-	public function get($file = '')
+	# 根据配置生成缩略图、裁切
+	public function get($file = '', $type = '', $id = '')
 	{
         $file = Dever::input('file', $file);
-        $array = $this->getFile($file);
+        $array = $this->getFile($file, $type, $id);
         $source = $array[0];
         $type = $array[1];
         $id = $array[2];
@@ -358,6 +358,7 @@ class View
         $path = $dest = $file;
         $handle = true;
         $local = false;
+        $image = array();
         if (strstr($file, '{uploadRes}') || strstr($file, $host)) {
             # 本地的
             $local = true;
@@ -385,6 +386,11 @@ class View
                 $file = $dest;
                 $handle = false;
             }
+        } else {
+            $data = parse_url($file);
+            $path = ltrim($data['path'], '/');
+            $host = $data['scheme'] . '://' . $data['host'] . '/';
+            $image['yun'] = Dever::db('upload/yun')->one(array('host' => $host));
         }
 
         if ($handle) {
@@ -414,10 +420,8 @@ class View
 		return $array[0];
 	}
 
-    private function getFile($file)
+    private function getFile($file, $type = false, $id = false)
     {
-        $type = $id = false;
-
         if (strstr($file, '_wp')) {
             $array = explode('_wp', $file);
             $type = 'wp';