Skip to content

Commit 8f47ac5

Browse files
committed
Refactor QR code download handler for improved layout and aesthetics; adjust dimensions, padding, and border styles
1 parent 4a824a5 commit 8f47ac5

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

src/components/Profile/Profile.jsx

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,51 +123,47 @@ function Card({ data }) {
123123
const svgStr = serializer.serializeToString(svg);
124124
const qrImg = new window.Image();
125125
qrImg.onload = function () {
126-
// HD scaling factor
127-
const scale = 3;
128-
const qrSize = qrImg.width * scale;
129-
const padding = 48 * scale; // more padding
130-
const borderRadius = 28 * scale;
131-
const borderWidth = 4 * scale; // thinner border
126+
// Target square size
127+
const size = 864;
128+
// QR code size inside the square (with padding)
129+
const qrSize = 640;
130+
const padding = (size - qrSize) / 2;
131+
const borderRadius = 60;
132+
const borderWidth = 8;
132133
const borderColor = '#0ea5e9';
133-
const textFontSize = 22 * scale;
134-
const textPaddingTop = 32 * scale;
135-
const textPaddingBottom = 18 * scale;
136-
const textHeight = textFontSize + textPaddingTop + textPaddingBottom;
137-
const size = qrSize + padding * 2;
138-
const totalHeight = size + textHeight;
134+
const textFontSize = 72;
135+
const textPaddingTop = 40;
136+
const text = 'Connect with me!';
139137
const canvas = document.createElement('canvas');
140138
canvas.width = size;
141-
canvas.height = totalHeight;
139+
canvas.height = size;
142140
const ctx = canvas.getContext('2d');
143141
// Draw rounded rectangle background
144142
ctx.save();
145143
ctx.beginPath();
146144
ctx.moveTo(borderRadius, 0);
147145
ctx.lineTo(size - borderRadius, 0);
148146
ctx.quadraticCurveTo(size, 0, size, borderRadius);
149-
ctx.lineTo(size, totalHeight - borderRadius);
150-
ctx.quadraticCurveTo(size, totalHeight, size - borderRadius, totalHeight);
151-
ctx.lineTo(borderRadius, totalHeight);
152-
ctx.quadraticCurveTo(0, totalHeight, 0, totalHeight - borderRadius);
147+
ctx.lineTo(size, size - borderRadius);
148+
ctx.quadraticCurveTo(size, size, size - borderRadius, size);
149+
ctx.lineTo(borderRadius, size);
150+
ctx.quadraticCurveTo(0, size, 0, size - borderRadius);
153151
ctx.lineTo(0, borderRadius);
154152
ctx.quadraticCurveTo(0, 0, borderRadius, 0);
155153
ctx.closePath();
156-
ctx.fillStyle = '#fff';
154+
ctx.fillStyle = '#ffffffff';
157155
ctx.fill();
158-
// Draw border
159156
ctx.lineWidth = borderWidth;
160157
ctx.strokeStyle = borderColor;
161158
ctx.stroke();
162159
ctx.restore();
163-
// Draw text above QR
164160
ctx.font = `bold ${textFontSize}px Arial`;
165-
ctx.fillStyle = '#15457B';
161+
ctx.fillStyle = '#0ea5e9';
166162
ctx.textAlign = 'center';
167163
ctx.textBaseline = 'top';
168-
ctx.fillText('Connect with me!', size / 2, textPaddingTop);
169-
// Draw QR image
170-
ctx.drawImage(qrImg, padding, textHeight, qrSize, qrSize);
164+
ctx.fillText(text, size / 2, textPaddingTop);
165+
const gapBelowText = 48;
166+
ctx.drawImage(qrImg, padding, textPaddingTop + textFontSize + gapBelowText, qrSize, qrSize);
171167
// Download
172168
const pngFile = canvas.toDataURL('image/png');
173169
const downloadLink = document.createElement('a');

0 commit comments

Comments
 (0)