Image.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\common\library\utils;
  10. use mall\utils\Check;
  11. use think\facade\Request;
  12. class Image{
  13. /**
  14. * 获取会员头像
  15. * @param $image
  16. * @param bool $root
  17. * @return string
  18. */
  19. public static function avatar($image,$root=true){
  20. if(Check::url($image)){
  21. return $image;
  22. }
  23. if(Request::domain() == "http://" || Request::domain() == "https://"){
  24. $domain = $root ? trim(env("web.app_web_url"),"/") : "";
  25. }else{
  26. $domain = $root ? trim(Request::domain(),"/") : "";
  27. }
  28. $default = $domain . "/static/images/avatar.png";
  29. $file = trim($image,"/");
  30. if(empty($image) || !file_exists($file)){
  31. return $default;
  32. }
  33. return $domain . '/' . $file;
  34. }
  35. }