<?php
namespace App\Libs;

class ImageProcess{

    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';
    const CHANNEL_SUFFIX = '?x-oss-process=image/resize,w_900/format,jpg';
    const BOOK_SUFFIX = '?x-oss-process=image/resize,w_200/format,jpg';
    /**
     * 客服消息图片
     */
    public static function  formatMsgImg($img_path) {
        return self::resize($img_path,self::MSG_SUFFIX);
    }
    /**
     * 分销后台展示图片
     */
    public static function  formatChannelImg($img_path) {
        return self::resize($img_path,self::CHANNEL_SUFFIX);
    }
    /**
     * 图书封面
     */
    public static function  formatBookImg($img_path) {
        return self::resize($img_path,self::BOOK_SUFFIX);
    }
    /**
     * 客服消息图片
     */
    public static function  resize($img_path,$suffix) {
        try{
            if(stripos($img_path,'?') !== false){
                $new_path = strstr($img_path,'?',true).$suffix;
            }else{
                $new_path = $img_path.$suffix;
            }
            return $new_path;
        } catch (\Exception $e) {
            \Log::info($e->getMessage());
        }
    }
}