dever 5 年 前
コミット
745e546ad3
4 ファイル変更48 行追加4 行削除
  1. 19 1
      README.md
  2. 18 0
      database/template.php
  3. 3 0
      package.json
  4. 8 3
      src/Api.php

+ 19 - 1
README.md

@@ -1,5 +1,23 @@
 # poster
 
-海报管理
+海报管理:根据传入的图片、文字生成一张图片,图片最好传入本地图片,如果是网络图片,会自动转存成本地图片,效率较慢,该组件需要upload组件支持
 
+使用方法:
 
+'''
+//文件名
+$filename = '1';
+//模板key
+$templateKey = 'k1';
+//模块数据包:数组key值为模块的key,数组value为文字或者图片
+$modelSet = array
+(
+	'desc' => '吞吞吐吐',
+	'pic' => '/www/grow/data/upload/1/2018/07/19/46d5b0c5c25c800cf197ea4f64f503f2.jpg',
+	'name' => '毒贩夫妇付',
+);
+//默认值为2,如果值为1,则每次都重新生成图片,否则只生成一次
+$update = 2;
+$img = Dever::load('poster/api')->get($filename, $templateKey, $modelSet, $update);
+
+'''

+ 18 - 0
database/template.php

@@ -1,5 +1,11 @@
 <?php
 
+$type = array
+(
+	'gd' => 'GD库',
+	'im' => 'ImageMagic库',
+);
+
 return array
 (
 	# 表名
@@ -47,6 +53,18 @@ return array
 			'list'		=> true,
 		),
 
+		'type'		=> array
+		(
+			'type' 		=> 'varchar-32',
+			'name' 		=> '使用的图形库',
+			'default' 	=> 'im',
+			'desc' 		=> '使用的图形库',
+			'match' 	=> 'is_string',
+			'update'	=> 'select',
+			'option'	=> $type,
+			'search'	=> 'select',
+		),
+
 		'background'		=> array
 		(
 			'type' 		=> 'varchar-150',

+ 3 - 0
package.json

@@ -0,0 +1,3 @@
+{
+	"rely": "upload"
+}

+ 8 - 3
src/Api.php

@@ -6,16 +6,21 @@ use Dever;
 class Api
 {
 	public function test()
+	{
+		return Dever::load('poster/api.gets', array('id' => 1));
+	}
+
+	public function gets()
 	{
 		return '<img src="' .$this->get('1', 'k1', array
 		(
 			'desc' => '吞吞吐吐',
-			'pic' => '/www/grow/data/upload/1/2018/07/19/46d5b0c5c25c800cf197ea4f64f503f2.jpg',
+			'pic' => 'http://wx.5dev.cn/wechat/data/upload/applet/code/2018/07/25/69_a2a3694c715c67b6823dedff8a7478bd.jpg',
 			'name' => '毒贩夫妇付',
 		)) . '" />';
 	}
 
-    public function get($name, $key, $set)
+    public function get($name, $key, $set, $update = 2)
 	{
 		$where['key'] = $key;
 		$template = Dever::db('poster/template')->one($where);
@@ -37,7 +42,7 @@ class Api
 				}
 
 				if ($config['param']) {
-					$result = Dever::load('upload/view')->create($config, $name, 'im');
+					$result = Dever::load('upload/view')->create($config, $name, $template['type'], $update);
 
 					return Dever::pic($result);
 				}