MCPcopy Create free account
hub / github.com/027xiguapi/code-box / makerQRPost

Function makerQRPost

utils/makerQRPost.ts:107–223  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

105
106 // 生成海报
107 const makerQRPost = (): void => {
108 const canvas = document.querySelector<HTMLCanvasElement>("#qrcodepostmaker")
109 const ctx = canvas.getContext("2d")
110 if (!ctx) return
111
112 const QRCodeData = ctx.getImageData(0, 0, canvas.width, canvas.height)
113 const title = document.title
114 const desc = document.head.querySelector('meta[name="description"]')
115 ? document.head.querySelector<HTMLMetaElement>(
116 'meta[name="description"]'
117 )!.content
118 : ""
119 const cardWidth = 360
120 const lineHeight = 1.6
121 const margin = 36
122 const titleStyle = 'Bold 18px "Microsoft YaHei"'
123 const descStyle = '16px "Microsoft YaHei"'
124
125 const titleArray = textComputer(
126 title,
127 titleStyle,
128 cardWidth - margin * 2,
129 ctx
130 )
131 const descArray = textComputer(desc, descStyle, cardWidth - margin * 2, ctx)
132
133 const cardHeight =
134 margin * 2.5 +
135 18 * titleArray.length * lineHeight +
136 16 * descArray.length * lineHeight +
137 (descArray.length ? margin / 2 : 0) +
138 300
139
140 canvas.width = cardWidth
141 canvas.height = cardHeight
142
143 const myGradient = ctx.createLinearGradient(0, 0, 0, cardHeight)
144 myGradient.addColorStop(0, "#2980B9")
145 myGradient.addColorStop(0.5, "#6DD5FA")
146 myGradient.addColorStop(1, "#FFFFFF")
147
148 ctx.fillStyle = myGradient
149 ctx.fillRect(0, 0, cardWidth, cardHeight)
150 ctx.fillStyle = "#FFFFFF"
151
152 ctx.beginPath()
153 ctx.arc(margin * 0.4, cardHeight - margin * 5, margin, 0, Math.PI * 2, true)
154 ctx.arc(
155 cardWidth - margin * 0.4,
156 cardHeight - margin * 3,
157 margin * 0.8,
158 0,
159 Math.PI * 2,
160 true
161 )
162 ctx.fillRect(0, cardHeight - margin * 5, cardWidth / 2, margin * 5)
163 ctx.fillRect(
164 cardWidth / 2,

Callers 1

makerQRCodeImgFunction · 0.70

Calls 2

textComputerFunction · 0.85
textWriterFunction · 0.85

Tested by

no test coverage detected