Skip to content

marker 自定义水印

介绍

生成一张自定义内容和位置水印的海报

demo

demo

使用

框架中使用

vue
<template>
	<img alt="marker" :src="markerSource" />
</template>

<script setup>
import { ref } from 'vue'
import { marker } from 'esay-watermark'

const markerSource = ref('')

marker({
	src: 'https://avatars.githubusercontent.com/u/65758455?v=4',
	text: 'jimmy',
	color: '#bdc3c7',
	size: 120,
	position: 'center',
	padding: 10,
}).then(source => {
	markerSource.value = source
})
</script>
<template>
	<img alt="marker" :src="markerSource" />
</template>

<script setup>
import { ref } from 'vue'
import { marker } from 'esay-watermark'

const markerSource = ref('')

marker({
	src: 'https://avatars.githubusercontent.com/u/65758455?v=4',
	text: 'jimmy',
	color: '#bdc3c7',
	size: 120,
	position: 'center',
	padding: 10,
}).then(source => {
	markerSource.value = source
})
</script>

原生页面中使用

html
<body>
	<script src="./watermark.min.js"></script>

	<img id="markerImage" alt="自定义水印" />

	<script>
		const { marker } = waterMarker // watermark 默认导出对象
		const markerImage = document.getElementById('markerImage')

		marker({
			src: 'https://avatars.githubusercontent.com/u/65758455?v=4',
			text: 'jimmy',
			color: '#bdc3c7',
			size: 120,
			position: 'CENTER',
			padding: 10,
		}).then(source => {
			markerImage.src = source
		})
	</script>
</body>
<body>
	<script src="./watermark.min.js"></script>

	<img id="markerImage" alt="自定义水印" />

	<script>
		const { marker } = waterMarker // watermark 默认导出对象
		const markerImage = document.getElementById('markerImage')

		marker({
			src: 'https://avatars.githubusercontent.com/u/65758455?v=4',
			text: 'jimmy',
			color: '#bdc3c7',
			size: 120,
			position: 'CENTER',
			padding: 10,
		}).then(source => {
			markerImage.src = source
		})
	</script>
</body>

API

属性名类型是否必填描述
srcstringyes图片地址(必填)
textstringyes水印文字
colorstringno水印颜色(默认 #c0c0c0
sizenumberno水印文字大小(默认 20)
paddingnumberno水印距离图片边缘的距离(默认 30)
output'jpeg' | 'png'no输出图片类型 支持 jpegpng (默认 jpeg
positionPositionno水印所处位置,默认 RIGHT_BOTTOM(右下)
type'fill'|'stroke'no文字的“填充模式”和“描边模式”(默认fill模式)
rotatenumberno旋转角度(默认 0)

其中 Position 属性具有以下属性值:

Position 属性值效果
LEFT_TOP左上
LEFT_CENTER左中
LEFT_BOTTOM坐下
CENTER_TOP中上
CENTER正中
CENTER_BOTTOM中下
RIGHT_TOP右上
RIGHT_CENTER右中
RIGHT_BOTTOM右下