阿里云图片处理工具类


import java.io.UnsupportedEncodingException;
import java.util.Base64;

/**
 * 阿里云图片处理工具类
 * @author caidongqu
 *
 */
public class AliyunOssImgUtils {

	 //列表上小图处理参数:将图自动裁剪成宽度为100,高度为100的效果图。
	public static final String MINI_IMG_PARAM = "?x-oss-process=image/resize,h_100,w_100";
//    public static final String SMALL_IMG_PARAM = "?x-oss-process=image/resize,m_fill,h_100,w_100";

    public static final String SMALL_IMG_PARAM = "?x-oss-process=image/resize,h_500,w_500";

    //中型图处理参数:将图缩略成宽度为300,高度为300,按短边优先。
    public static final String MIDDLE_IMG_PARAM = "?x-oss-process=image/resize,h_1080,w_1080";

//    //水印样式--固定样式
    public static final String WARTER_MARK_TEXT_A = "?x-oss-process=style/watermark";

    //水印样式--动态样式
    public static final String WARTER_MARK_TEXT_B = "?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,size_30,color_FFFFFF,text_";
    /**
     * 取视频第一帧图片参数
     * <br>参照:https://help.aliyun.com/document_detail/64555.html?spm=a2c4g.11186623.6.1394.eb8635a8EAXQYt
     */
    public static final String VIDEO_SNAPSHOT_PARAM="?x-oss-process=video/snapshot,t_0,f_jpg,w_0,h_0,m_fast,ar_auto";

    public static String getWarterUrl( String oldImg,String text ){
    	String imgUrl = "";
    	try{
    		String safeText = safeUrlBase64Encode(text);
    		imgUrl = oldImg + WARTER_MARK_TEXT_B + safeText;
    	}catch(UnsupportedEncodingException e){
    		imgUrl = oldImg + WARTER_MARK_TEXT_A;
    	}
    	return imgUrl;
    }

    public static String safeUrlBase64Encode(String text) throws UnsupportedEncodingException{
    	byte[] data = text.getBytes("UTF-8");
		String encodeBase64 = Base64.getEncoder().encodeToString(data);
		String safeBase64Str = encodeBase64.replace('+', '-');
		safeBase64Str = safeBase64Str.replace('/', '_');
		safeBase64Str = safeBase64Str.replaceAll("=", "");
		return safeBase64Str;
	}

//    public static void main(String[] args) {
//    	System.out.println(getWarterUrl("https://feicuiyanpin-goods-test.oss-cn-shenzhen.aliyuncs.com/20180719/100072/detail/100072_detail_20180719172329_ios_0.jpg","ZY3180719011"));
//	}

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

超人在良家-阿启

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值