123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace Poster\Src;
- use Dever;
- class Api
- {
- public function test()
- {
- return Dever::load('poster/api.gets', array('id' => 1));
- }
- public function gets()
- {
- $name = "专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍";
- $name = Dever::addstr($name, 11, "11");
- return '<img src="' .$this->get('1', 'k1', array
- (
- 'desc' => '吞吞吐吐',
- //'pic' => 'http://wx.5dev.cn/wechat/data/upload/applet/code/2018/07/26/69_48f3901dc1d6f839a12967f9b49f5f9c.jpg',
- 'name' => $name,
- ), 1) . '" />';
- }
- public function get($name, $key, $set, $update = false, $num = 1)
- {
- if (strstr($key, ',') || is_numeric($key)) {
- $where['ids'] = $key;
- } else {
- $where['key'] = $key;
- }
- $template = Dever::db('poster/template')->getAll($where);
- $key = array_rand($template, 1);
- $template = $template[$key];
- if ($template) {
- if (!$update) {
- $update = $template['update'];
- }
- $where = array();
- $where['template_id'] = $template['id'];
- $model = Dever::db('poster/model')->state($where);
- if ($model) {
- $config = array();
- $config['background'] = Dever::local($template['background']);
- $config['param'] = array();
- foreach ($model as $k => $v) {
- $param = $this->getConfig($v, $set);
- if ($param) {
- array_push($config['param'], $param);
- }
- }
- if ($config['param']) {
- $result = Dever::load('upload/view')->create($config, $name, $template['type'], $update);
- return Dever::pic($result);
- }
- } else {
- return Dever::pic($template['background']);
- }
- }
- return false;
- }
- private function getConfig($value, $set)
- {
- $key = $value['key'];
- $param = array();
- if (!isset($set[$key]) && $value['value']) {
- $set[$key] = $value['value'];
- }
- if (isset($set[$key])) {
- if ($value['position_type'] == 8) {
- $position = explode(',', $value['position']);
- } else {
- $position = $value['position_type'];
- }
-
- if ($value['type'] == 1) {
- $param['method'] = 'mark';
- $param['water'] = $set[$key];
- $param['position'] = $position;
- $param['width'] = $value['width'];
- $param['height'] = $value['height'];
- } elseif ($value['type'] == 2) {
- $param['method'] = 'txt';
- $param['name'] = $set[$key];
- $param['color'] = $value['color'];
- $param['position'] = $position;
- //$param['top'] = $position[1];
- //$param['left'] = $position[2];
- $param['size'] = $value['size'];
- $param['angle'] = $value['angle'];
-
- $fonts = array
- (
- 1 => 'PingFang_Regular.ttf',
- 2 => 'PingFang_Bold.ttf',
- 3 => 'PingFang_Medium.ttf',
- );
- $param['font'] = dirname(__FILE__) . DIRECTORY_SEPARATOR . '../fonts/'.$fonts[$value['fonts']];
- }
- }
- return $param;
- }
- }
|