1)); } public function gets() { $name = "专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍"; $name = Dever::addstr($name, 11, "11"); return ''; } # 获取同一个key下的多个模板 public function getList($key) { $where['key'] = $key; $template = Dever::db('poster/template')->getAll($where); return $template; } # 获取某个模板 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); $total = count($template); if ($num > $total) { $num = $total; } $key = array_rand($template, 1); if (is_array($key)) { $result = array(); foreach ($key as $k => $v) { $result[] = $this->getTemplate($set, $template, $v, $name, $update); } return $result; } else { return $this->getTemplate($set, $template, $key, $name, $update); } return false; } private function getTemplate($set, $template, $key, $name, $update) { $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'] = ''; if (isset($set['width']) && $set['width']) { $template['width'] = $set['width']; } if (isset($set['height']) && $set['height']) { $template['height'] = $set['height']; } if (isset($set['background']) && $set['background']) { $config['background'] = Dever::local($set['background']); unset($set['background']); } elseif ($template['create'] == 2 && $template['background']) { $config['background'] = Dever::local($template['background']); } elseif ($template['create'] == 1) { $config['background'] = array ( $template['width'], $template['height'] ); } $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('poster/lib/img')->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])) { if ($value['type'] == 1 && $value['value_pic']) { $set[$key] = Dever::local($value['value_pic']); } else { $set[$key] = $value['value']; } } if (isset($set[$key])) { if ($value['position_type'] == 10) { $position = explode(',', $value['position']); } else { $position = $value['position_type']; } $offset = explode(',', $value['offset']); if ($value['type'] == 1) { $param['method'] = 'mark'; $param['water'] = $set[$key]; $param['position'] = $position; $param['offset'] = $offset; $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['offset'] = $offset; //$param['top'] = $position[1]; //$param['left'] = $position[2]; $param['size'] = $value['size']; $param['angle'] = $value['angle']; if (isset($value['text_width']) && $value['text_width'] > 0) { $param['width'] = $value['text_width']; } $param['font'] = $this->getFont($value['fonts'], 1); } } return $param; } # 字体 public function getFont($value, $type = 1) { $fonts = array ( //1 => 'simsun.ttc', 1 => 'PingFang_Regular.ttf', 2 => 'PingFang_Bold.ttf', 3 => 'PingFang_Medium.ttf', ); if ($type == 1) { return dirname(__FILE__) . DIRECTORY_SEPARATOR . '../fonts/'.$fonts[$value]; } else { return dirname(__FILE__) . DIRECTORY_SEPARATOR . '../fonts/'.$fonts[$value]; } } }