1.0.4 • Published 2 years ago

pic-template v1.0.4

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

PicTemplate

npm npm

A Vue Component for html2canvas

Vue support

Supports only Vue >= 2

Installation and usage

npm install --save pic-template
<PicTemplate
  ref="boxRef"
  v-model="loading"
  :data="data"
  @error="onError"
/>

Global Import

import PicTemplate from 'pic-template'
Vue.use(PicTemplate)

Import on Demand

import PicTemplate from 'pic-template'

new Vue({
  components: {
    PicTemplate
  },
  data() {
    return {
      loading: false,
      options: {
        debug: true,
        autoRender: false
      },
      data: {
        bgImage: '',
        list: [
          {
            type: 1, // 1-text 2-image
            content: 'ABC Number CBA', // text or image url
            fontSize: 100,
            fontColor: 'white',
            x: 503,
            y: 676,
            alignment: 2, // 1-left 2-center 3-right
            style: {
              width: '120px'
            }
          }
        ]
      }
    }
  },
  methods: {
    async render() {
      const canvas = await this.$refs['boxRef'].render()
      console.log('res:', canvas)
    },
    onError(error) {
      console.log(error)
    }
  }
});

PicTemplate Props

AttributeRequiredTypeDefault
v-modelnobooleanfalse
datayesobject (PicTemplateData)-
optionsnoobject (PicTemplateOps)-

PicTemplate Events

EventDescriptionArguments
errorerror(error: string, code: number)

Code

CodeDescription
101timeout
102setData error
103render error
104image load error

PicTemplate Types

PicTemplateData {
  bgImage: string;
  list: Array<{
    type: 1 | 2; // 1-text 2-image
    content: string; // text or image url
    fontSize?: number'
    fontColor?: string;
    x: number;
    y: number;
    alignment: 1 | 2 | 3; // 1-left 2-center 3-right
    style?: {};
  }>;
}
PicTemplateOps {
  debug?: boolean; // default false
  imageType?: string; // default image/png
  autoRender?: boolean; // default true
  renderType?: 'blob' | 'base64'; // default base64
  timeout?: null | number; // default null
  renderEnd?: ({
    renderImage: string;
    canvas: HTMLCanvasElement;
  }) => void;
}
1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago