feat: 印章生成器新增三种效果 — 防伪纹路(同心细线+外圈放射线,source-atop仅墨区), 毛边(轮廓随机撕裂), 做旧(斑驳磨损), 可多选叠加
This commit is contained in:
1 parent
98f8f61137
commit
bcaf750a74
1 file changed
+137
@@ -10,6 +10,10 @@ const genHist = useGenHistory('seal-maker');
|
|||||||
|
|
||||||
// ============ 印章参数 ============
|
// ============ 印章参数 ============
|
||||||
const style = ref<'circle-star' | 'circle-text'>('circle-star');
|
const style = ref<'circle-star' | 'circle-text'>('circle-star');
|
||||||
|
// 效果(可叠加)
|
||||||
|
const effectPattern = ref(false); // 防伪纹路
|
||||||
|
const effectFrayed = ref(false); // 毛边
|
||||||
|
const effectAged = ref(false); // 做旧
|
||||||
const mainText = ref('在线工具大全示例专用章');
|
const mainText = ref('在线工具大全示例专用章');
|
||||||
const subText = ref('合同专用章');
|
const subText = ref('合同专用章');
|
||||||
const sealSize = ref(300);
|
const sealSize = ref(300);
|
||||||
@@ -128,6 +132,86 @@ function renderSeal() {
|
|||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---- 防伪纹路:只在有墨区域叠加同心细线 + 外圈放射短线 ----
|
||||||
|
if (effectPattern.value) {
|
||||||
|
ctx.save();
|
||||||
|
ctx.globalCompositeOperation = 'source-atop';
|
||||||
|
ctx.strokeStyle = 'rgba(0,0,0,0.15)';
|
||||||
|
ctx.lineWidth = Math.max(0.6, size * 0.003);
|
||||||
|
const gap = Math.max(3, size * 0.014);
|
||||||
|
for (let rr = gap; rr < Rr; rr += gap) {
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(cx, cy, rr, 0, Math.PI * 2);
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
// 外圈放射状防伪短线
|
||||||
|
const spokes = 96;
|
||||||
|
ctx.beginPath();
|
||||||
|
for (let i = 0; i < spokes; i++) {
|
||||||
|
const a = (i / spokes) * Math.PI * 2;
|
||||||
|
const r0 = Rr * 0.9;
|
||||||
|
const r1 = Rr * 0.985;
|
||||||
|
ctx.moveTo(cx + Math.cos(a) * r0, cy + Math.sin(a) * r0);
|
||||||
|
ctx.lineTo(cx + Math.cos(a) * r1, cy + Math.sin(a) * r1);
|
||||||
|
}
|
||||||
|
ctx.stroke();
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 毛边效果:沿外轮廓与文字边缘随机撕裂缺口 ----
|
||||||
|
if (effectFrayed.value) {
|
||||||
|
ctx.save();
|
||||||
|
ctx.globalCompositeOperation = 'destination-out';
|
||||||
|
ctx.fillStyle = 'black';
|
||||||
|
// 外圆轮廓毛刺
|
||||||
|
const nEdge = Math.round(size / 4);
|
||||||
|
for (let i = 0; i < nEdge; i++) {
|
||||||
|
const a = Math.random() * Math.PI * 2;
|
||||||
|
const rr = Rr + (Math.random() - 0.5) * ringW * 1.8;
|
||||||
|
const sz = 0.6 + Math.random() * (size * 0.011);
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(cx + Math.cos(a) * rr, cy + Math.sin(a) * rr, sz, 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
|
}
|
||||||
|
// 文字环带毛刺
|
||||||
|
const nText = Math.round(size / 6);
|
||||||
|
for (let i = 0; i < nText; i++) {
|
||||||
|
const a = Math.random() * Math.PI * 2;
|
||||||
|
const rr = Rr * 0.76 + (Math.random() - 0.5) * fontPx * 1.2;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(cx + Math.cos(a) * rr, cy + Math.sin(a) * rr, 0.5 + Math.random() * (size * 0.006), 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
|
}
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 做旧效果:全局斑驳磨损(墨色不均 + 随机磨损块) ----
|
||||||
|
if (effectAged.value) {
|
||||||
|
ctx.save();
|
||||||
|
ctx.globalCompositeOperation = 'destination-out';
|
||||||
|
ctx.fillStyle = 'black';
|
||||||
|
const dots = Math.round((size * size) / 500);
|
||||||
|
for (let i = 0; i < dots; i++) {
|
||||||
|
const x = Math.random() * size;
|
||||||
|
const y = Math.random() * size;
|
||||||
|
const sz = 0.4 + Math.random() * 1.6;
|
||||||
|
ctx.globalAlpha = 0.25 + Math.random() * 0.75;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(x, y, sz, 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
|
}
|
||||||
|
const patches = Math.round(size / 25);
|
||||||
|
for (let i = 0; i < patches; i++) {
|
||||||
|
const x = Math.random() * size;
|
||||||
|
const y = Math.random() * size;
|
||||||
|
ctx.globalAlpha = 0.12 + Math.random() * 0.38;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(x, y, 1 + Math.random() * size * 0.02, 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
|
}
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
|
|
||||||
sealDataUrl.value = c.toDataURL('image/png');
|
sealDataUrl.value = c.toDataURL('image/png');
|
||||||
const b64 = sealDataUrl.value.split(',')[1];
|
const b64 = sealDataUrl.value.split(',')[1];
|
||||||
const bin = atob(b64);
|
const bin = atob(b64);
|
||||||
@@ -153,6 +237,9 @@ function resetSeal() {
|
|||||||
sealSize.value = 300;
|
sealSize.value = 300;
|
||||||
color.value = '#E60012';
|
color.value = '#E60012';
|
||||||
invert.value = false;
|
invert.value = false;
|
||||||
|
effectPattern.value = false;
|
||||||
|
effectFrayed.value = false;
|
||||||
|
effectAged.value = false;
|
||||||
renderSeal();
|
renderSeal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,6 +493,13 @@ onMounted(() => {
|
|||||||
<div class="sm-panel">
|
<div class="sm-panel">
|
||||||
<div class="sm-panel-title">⚙️ 印章参数</div>
|
<div class="sm-panel-title">⚙️ 印章参数</div>
|
||||||
<div class="sm-field">
|
<div class="sm-field">
|
||||||
|
<label class="sm-label">印章效果 <span class="sm-hint">可多选叠加</span></label>
|
||||||
|
<div class="sm-effects">
|
||||||
|
<label class="sm-effect-item"><input v-model="effectPattern" type="checkbox" @change="renderSeal"> 🛡️ 防伪纹路</label>
|
||||||
|
<label class="sm-effect-item"><input v-model="effectFrayed" type="checkbox" @change="renderSeal"> 毛边效果</label>
|
||||||
|
<label class="sm-effect-item"><input v-model="effectAged" type="checkbox" @change="renderSeal"> ⏳ 做旧效果</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<label class="sm-label">印章样式</label>
|
<label class="sm-label">印章样式</label>
|
||||||
<select v-model="style" class="sm-select" @change="renderSeal">
|
<select v-model="style" class="sm-select" @change="renderSeal">
|
||||||
<option value="circle-star">圆形公章(五角星)</option>
|
<option value="circle-star">圆形公章(五角星)</option>
|
||||||
@@ -559,6 +653,49 @@ onMounted(() => {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped>
|
||||||
|
.sm-effects {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
|
||||||
|
.sm-effect-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
font-size: 13px;
|
||||||
|
padding: 7px 10px;
|
||||||
|
border: 1px solid rgba(128, 128, 128, 0.25);
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.15s, background 0.15s;
|
||||||
|
user-select: none;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
border-color: rgba(128, 128, 128, 0.45);
|
||||||
|
}
|
||||||
|
|
||||||
|
input:checked + * {
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:has(input:checked) {
|
||||||
|
border-color: #e60012;
|
||||||
|
background: rgba(230, 0, 18, 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
accent-color: #e60012;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.sm-hint {
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: 400;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
.sm-root {
|
.sm-root {
|
||||||
padding-bottom: 16px;
|
padding-bottom: 16px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user