ImageProcess.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Libs;
  3. class ImageProcess{
  4. const MSG_SUFFIX = '?x-oss-process=image/resize,m_lfit,h_90/format,jpg/crop,x_0,y_0,w_90,h_90,g_se';
  5. const CHANNEL_SUFFIX = '?x-oss-process=image/resize,w_900/format,jpg';
  6. const BOOK_SUFFIX = '?x-oss-process=image/resize,w_200/format,jpg';
  7. /**
  8. * 客服消息图片
  9. */
  10. public static function formatMsgImg($img_path) {
  11. return self::resize($img_path,self::MSG_SUFFIX);
  12. }
  13. /**
  14. * 分销后台展示图片
  15. */
  16. public static function formatChannelImg($img_path) {
  17. return self::resize($img_path,self::CHANNEL_SUFFIX);
  18. }
  19. /**
  20. * 图书封面
  21. */
  22. public static function formatBookImg($img_path) {
  23. return self::resize($img_path,self::BOOK_SUFFIX);
  24. }
  25. /**
  26. * 客服消息图片
  27. */
  28. public static function resize($img_path,$suffix) {
  29. try{
  30. if(stripos($img_path,'?') !== false){
  31. $new_path = strstr($img_path,'?',true).$suffix;
  32. }else{
  33. $new_path = $img_path.$suffix;
  34. }
  35. return $new_path;
  36. } catch (\Exception $e) {
  37. \Log::info($e->getMessage());
  38. }
  39. }
  40. }