Img.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. }
  61. return $host . str_replace(DEVER_PROJECT_PATH, '', $file);
  62. $file = Dever::pic($file);
  63. return $file;
  64. }
  65. }