package jnpf.util.attendance;

import lombok.extern.slf4j.Slf4j;

import java.util.Base64;

@Slf4j
public class OcsWatermarkUtils {

    /**
     * 水印样式
     */
    private static final String OCS_WATERMARK = "?watermark/2/text/%s/fill/I0Y1RjVGNQ==/fontsize/100/dissolve/17/gravity/northeast/dx/20/dy/20/batch/1/spacing/100/degree/45";

    /**
     * 生成样式URL
     *
     * @param value 水印文案
     * @return 返回完整水印图片url
     */
    public static String watermarkByStr(String value) {
        return String.format(OCS_WATERMARK, processBase64String(convertToBase64(value)));
    }

    public static String convertToBase64(String imagePath) {
        return Base64.getEncoder().encodeToString(imagePath.getBytes());
    }

    public static String processBase64String(String base64EncodedString) {
        String modifiedString = base64EncodedString.replace("+", "-");
        modifiedString = modifiedString.replace("/", "_");
        modifiedString = modifiedString.replace("=", "");
        return modifiedString;
    }
}
