Img.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Poster\Lib;
  3. use Dever;
  4. use Dever\Support\Img as Handle;
  5. class Img
  6. {
  7. /**
  8. * create 生成图片
  9. * @param array $config
  10. * @param string $filename
  11. *
  12. * @return mixed
  13. */
  14. public function create($config = array(), $filename = '', $type = 'gd', $update = 2)
  15. {
  16. $this->img = isset($this->img) ? $this->img : new Handle();
  17. /*
  18. $config = array
  19. (
  20. 'background' => '/www/grow/data/upload/1/2018/07/19/a49fe8914df0eada4d4b7d530d7fa5ba.jpg',
  21. 'param' => array
  22. (
  23. 0 => array
  24. (
  25. 'method' => 'mark',
  26. 'water' => '/www/grow/data/upload/1/2018/07/19/46d5b0c5c25c800cf197ea4f64f503f2.jpg',
  27. //left,top
  28. 'position' => array(100,200),
  29. 'width' => 100,
  30. 'height' => 100,
  31. ),
  32. 1 => array
  33. (
  34. 'method' => 'txt',
  35. 'name' => 'test文字',
  36. 'color' => '#FF0000',
  37. 'position' => array(100,200),
  38. 'size' => 50,
  39. 'angle' => 0,
  40. 'font' => '/www/grow/config/fonts/simsun.ttc',
  41. ),
  42. ),
  43. );
  44. */
  45. if (!$filename) {
  46. $filename = Dever::id();
  47. }
  48. $file = Dever::pathDay('upload/poster', false) . md5($filename) . '.jpg';
  49. if (!is_file($file) || $update == 1) {
  50. $this->img->setType($type);
  51. $result = $this->img->init($config['background'], $config['param'], true, $file);
  52. if ($result) {
  53. $file = array_pop($result);
  54. }
  55. } else {
  56. }
  57. $host = str_replace(DEVER_PROJECT . '/' . DEVER_APP_NAME . '/', '', Dever::config('host')->base);
  58. if (strstr($file, '/share/dc/data/')) {
  59. return $host . str_replace('/share/dc/data/', '', $file);
  60. } else {
  61. return Dever::pic($file);
  62. }
  63. return $host . str_replace(DEVER_PROJECT_PATH, '', $file);
  64. $file = Dever::pic($file);
  65. return $file;
  66. }
  67. }