更新记录

1.1.6(2023-05-19)

更新文档

1.1.5(2023-05-19)

修复评论里说的空白问题,因为uni.getImageInfo 是异步的,之前没做处理,这次找到原因了,磕头认罪Orz。

1.1.4(2023-05-19)

完善说明文档

查看更多

平台兼容性

Vue2 Vue3
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.6.0 × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × × ×

修复了网络速度慢图片加载慢的时候生成不出来的问题,怪我文档看的不仔细,磕头认罪Orz 另外大家一定要注意配置微信安全域名,感谢支持!

导入
import Poster from '../../../components/zhangyuhao-poster/Poster.vue'
在components中声明
export default {
    components: {
        Poster
    }
}
在template中使用
<poster ref="poster" :list="list" background-color="#FFF" :width="750" :height="1334"
            @on-success="posterSuccess" @on-error="posterError"></poster>
调用create函数,生成图片
// 生成图片
this.$nextTick(() => {
    // 视情况而定是否要使用 $nextTick()
    this.$refs.poster.create();
})
list参数说明
参数名 必选 类型 说明
type string 类型,可选值:image(图片),text(文字),textarea(多行文字)
x number x轴位置
y number y轴位置
path string 图片路径,type为image时必填
width string type为image时指定图片宽度,type为textarea时指定换行的宽度
height string type为image时必填指定图片高度,type为textarea时指定文本区域高度,溢出展示“...”
rotate number 旋转角度
shape string 可选值:circle 圆形
area object 绘制范围,超出该范围会被剪裁掉 该属性与shape暂时无法同时使用,area存在时,shape失效;例如: {x:10,y:10,width:100,height:100}
text string 文本内容,type为text或textarea时必填
color string 文本颜色
size number 文本字体大小
lineSpace number 行间距,type为textarea时有效
textBaseline string 基线 默认top 可选值:'top'、'bottom'、'middle'、'normal'
代码示例
<template>
    <view>
        <button @click="start()">生成</button>
        <!-- 此处用于展示生成的图片 -->
        <image :src="poster" style="width: 750rpx;height: 1334rpx;"></image>
        <!-- 生成图片 -->
        <poster ref="poster" :list="list" background-color="#FFF" :width="750" :height="1334"
            @on-success="posterSuccess" @on-error="posterError"></poster>

    </view>
</template>

<script>
    import Poster from '../../../components/zhangyuhao-poster/Poster.vue'
    export default {
        components: {
            Poster
        },
        data() {
            return {
                poster: '',
                list: []
            };
        },
        methods: {
            posterError(err) {
                console.log(err)
            },
            posterSuccess(url) {
                // 生成成功,会把临时路径在这里返回
                this.poster = url;
                console.log(url)
            },
            start() {
                // 赋值需要渲染的信息
                this.list = [{
                        type: 'image',
                        // path替换成你自己的图片,注意需要在小程序开发设置中配置域名
                        path: 'https://xxxxxxx.aliyuncs.com/test/1.jpg',
                        x: 0,
                        y: 0,
                        width: 750,
                        height: 750
                    },
                    {
                        type: 'image',
                        path: 'https://xxxxxxx.aliyuncs.com/test/1.jpg',
                        x: (750 - 200) / 2,
                        y: 880,
                        width: 200,
                        height: 200
                    },
                    {
                        type: 'textarea',
                        width: 700,
                        height: 150,
                        x: 20,
                        y: 780,
                        text: '童装卫衣2023春季新款',
                        size: 24,
                        color: '#000'
                    }
                ];
                // 生成图片
                this.$nextTick(() => {
                    // 要放在$nextTick()里,不然会空白
                    this.$refs.poster.create();
                })
            }
        }
    }
</script>

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问