1.0.1 • Published 5 years ago

auto-image-watermark v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

海报生成 H5 端 SDK

安装说明

npm install auto-image-watermark

快速使用

import {create} from 'auto-image-watermark';
const H5 = create({
      width: 375,
      height: 600,
      backgroundColor: '#fff',
      debug: false,
      pixelRatio: 2,
      blocks: [{
          width: 650,
          height: 300,
          x: 1,
          y: 2,
          borderWidth: 4,
          borderColor: '#000',
          borderRadius: 30,
          backgroundColor: '#fff',
          text: {
            text: [{
                x: 12,
                y: 40,
                text: '块中的文字',
                fontSize: 35,
                color: '#f00',
                width: 300
              },
              {
                x: 182,
                y: 90,
                text: '过长文字缩略',
                fontSize: 35,
                color: '#f76',
                width: 300
              }
            ]

          },
          zIndex: 1
        },
        {
          width: 650,
          height: 200,
          x: 10,
          y: 400,
          borderWidth: 6,
          borderColor: '#ff00ff',
          borderRadius: 50,
          backgroundColor: '#ff0',
          opacity: 0.5,
          zIndex: 2
        },
      ],
      lines: [{
        startX: 250,
        startY: 250,
        endX: 550,
        endY: 250,
        width: 9,
        color: 'green',
        zIndex: 128
      }],
      texts: [{
        x: 113,
        y: 132,
        text: 'hello world',
        fontSize: 57,
        baseLine: 'middle',
        textAlign: 'left',
        color: 'rgba(255,0,0)',
        zIndex: 8
      }, ],
      images: [{
          width: 276,
          x: 74,
          y: 170,
          borderRadius: 12,
          borderColor: '#f30',
          borderWidth: 4,
          url: 'https://lc-I0j7ktVK.cn-n1.lcfile.com/02bb99132352b5b5dcea.jpg',
          zIndex: 40
        }
      ]
    });

API

create(config) => Promise<{base64:string}>;

create 参数说明

参数必填类型说明
widthNumber画布宽度
heightNumber画布高度
backgroundColorString画布背景色
blocksArray绘制块 ,具体参见blocks参数详解
linesArray绘制线 ,具体参见lines参数详解
textsArray绘制文字 ,具体参见texts参数详解
imagesArray绘制图片 ,具体参见images参数详解

blocks 参数说明

参数必填类型说明
xNumber块的横坐标
yNumber块的纵坐标
widthNumber块宽度
heightNumber块高度
backgroundColorString块背景色
borderWidthNumber边框宽度
borderColorString边框颜色
borderRadiusNumber圆角
textObject块里面可以填充文字,text.text参考texts字段解释
zIndexNumber层级,越大越高

lines 参数说明

参数必填类型说明
startXNumber起始横坐标
startYNumber起始纵坐标
endXNumber终点横坐标
endYNumber终点纵坐标
widthNumber线的宽度
colorString线的颜色
zIndexNumber层级,越大越高

texts 参数说明

参数必填类型说明
xNumber文字横坐标
yNumber文字纵坐标
textNumber文字内容
fontSizeNumber文字大小
colorString文字颜色
opacityNumber文字透明度
widthNumber文字最大宽度
baseLineStringtop|bottom|middle|alphabetic|hanging 基线对齐方式
textAlignStringstart|end|left|center|right 对齐方式
fontFamilyString文字字体
fontWeightString文字加粗
fontStyleString文字倾斜
zIndexNumber层级,越大越高

images 参数说明

参数必填类型说明
xNumber图片横坐标
yNumber图片纵坐标
urlString图片地址
widthNumber图片宽度
heightNumber图片高度
borderWidthNumber边框宽度
borderColorString边框颜色
borderRadiusNumber圆角
zIndexNumber层级,越大越高

注意事项

1.zIndex代表block、image、line、text之间的层级关系,层级越大,显示层级在越靠上; 2.blocks中的text的zIndex无效; 3.images中需要生成圆形图片则设置图片width、height、borderRadius三者相等即可; 4.单位统一(px);

CHANGELOG

V1.0.1

  1. 新增圆形block,优化生成圆形图片方式;
  2. 优化文字宽度省略问题;
  3. 优化画布和画板的高宽;

V1.0.0

  1. 海报生成sdk-h5端;