2019年5月

利用canvas给网页添加文字水印

    addWaterMarker('我 是 水 印');
    function addWaterMarker(str, w=300, h=300, c='#999999') {
    // 创建一个 Canvas 元素
    var canvas = document.createElement('canvas');
    canvas.width = w; // 设置 Canvas 的宽度
    canvas.height = h; // 设置 Canvas 的高度

    // 获取 Canvas 的 2D 上下文
    var ctx = canvas.getContext('2d');

    // 设置文本样式
    ctx.font = '18px Arial';
    ctx.fillStyle = c;
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';

    // 设置字体水平度
    ctx.rotate(30 * Math.PI / 180);

    // 绘制文本
    ctx.fillText(str, canvas.width / 2, canvas.height / 2);

    // 将 Canvas 转换为 PNG 图片
    var dataURL = canvas.toDataURL('image/png');
    // 创建body下的div元素,使用固定定位,将canvas所谓背景图并铺满全屏
    let node = document.createElement("div");
    node.style.pointerEvents = "none";
    // 设置元素固定定位,并将宽高设置为100%,铺满全屏
    node.style.position = "fixed";
    node.style.width = "100%";
    node.style.height = "100%";
    node.style.top = "0";
    node.style.left = "0";
    node.style.opacity = "0.2";
    node.style.zIndex = "998";
    // 将canvas作为背景图,并设置左上开始,重复铺满全屏
    node.style.background = "url(" + dataURL + ") left top repeat";
    // 将创建的元素插入body中,作为body的子元素
    document.body.appendChild(node);
}

Let’s Encrypt 证书自动更新

Let’s Encrypt 每次申请仅3个月有效期
更新命令:certbot renew

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
0 0 1 */2 * certbot renew --quiet --force-renewal

certbot安装
yum -y install yum-utils
yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional
执行certbot certonly测试安装是否正确

PS:我也是随便复制的,只是想到了Let’s Encrypt的自动更新便百度了一下 :)

解决ueditor复制section丢失class及style样式问题

在复制微信的文章格式到ueditor时发现section标签中的style和class属性丢失,严重影响美观。
原因:ueditor中有xss过滤器,默认启用,按照配置文件中的白名单列表,不在其中的将去除。

解决:
修改ueditor文件中whiteList中找到section那项,把class和style加入白名单。