Api.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace Poster\Src;
  3. use Dever;
  4. class Api
  5. {
  6. public function test()
  7. {
  8. return Dever::load('poster/api.gets', array('id' => 1));
  9. }
  10. public function gets()
  11. {
  12. $name = "专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍专家介绍";
  13. $name = Dever::addstr($name, 11, "11");
  14. return '<img src="' .$this->get('1', 'k1', array
  15. (
  16. 'desc' => '吞吞吐吐',
  17. //'pic' => 'http://wx.5dev.cn/wechat/data/upload/applet/code/2018/07/26/69_48f3901dc1d6f839a12967f9b49f5f9c.jpg',
  18. 'name' => $name,
  19. ), 1) . '" />';
  20. }
  21. public function get($name, $key, $set, $update = false, $num = 1)
  22. {
  23. if (strstr($key, ',') || is_numeric($key)) {
  24. $where['ids'] = $key;
  25. } else {
  26. $where['key'] = $key;
  27. }
  28. $template = Dever::db('poster/template')->getAll($where);
  29. $key = array_rand($template, 1);
  30. $template = $template[$key];
  31. if ($template) {
  32. if (!$update) {
  33. $update = $template['update'];
  34. }
  35. $where = array();
  36. $where['template_id'] = $template['id'];
  37. $model = Dever::db('poster/model')->state($where);
  38. if ($model) {
  39. $config = array();
  40. $config['background'] = Dever::local($template['background']);
  41. $config['param'] = array();
  42. foreach ($model as $k => $v) {
  43. $param = $this->getConfig($v, $set);
  44. if ($param) {
  45. array_push($config['param'], $param);
  46. }
  47. }
  48. if ($config['param']) {
  49. $result = Dever::load('upload/view')->create($config, $name, $template['type'], $update);
  50. return Dever::pic($result);
  51. }
  52. } else {
  53. return Dever::pic($template['background']);
  54. }
  55. }
  56. return false;
  57. }
  58. private function getConfig($value, $set)
  59. {
  60. $key = $value['key'];
  61. $param = array();
  62. if (!isset($set[$key]) && $value['value']) {
  63. $set[$key] = $value['value'];
  64. }
  65. if (isset($set[$key])) {
  66. if ($value['position_type'] == 8) {
  67. $position = explode(',', $value['position']);
  68. } else {
  69. $position = $value['position_type'];
  70. }
  71. if ($value['type'] == 1) {
  72. $param['method'] = 'mark';
  73. $param['water'] = $set[$key];
  74. $param['position'] = $position;
  75. $param['width'] = $value['width'];
  76. $param['height'] = $value['height'];
  77. } elseif ($value['type'] == 2) {
  78. $param['method'] = 'txt';
  79. $param['name'] = $set[$key];
  80. $param['color'] = $value['color'];
  81. $param['position'] = $position;
  82. //$param['top'] = $position[1];
  83. //$param['left'] = $position[2];
  84. $param['size'] = $value['size'];
  85. $param['angle'] = $value['angle'];
  86. $fonts = array
  87. (
  88. 1 => 'PingFang_Regular.ttf',
  89. 2 => 'PingFang_Bold.ttf',
  90. 3 => 'PingFang_Medium.ttf',
  91. );
  92. $param['font'] = dirname(__FILE__) . DIRECTORY_SEPARATOR . '../fonts/'.$fonts[$value['fonts']];
  93. }
  94. }
  95. return $param;
  96. }
  97. }