feat: add QR code generator tool
Add a sixth tool with live SVG preview, customizable foreground/background colors, error correction level, margin control, and export as PNG (256–2048px) or SVG. URL params enable shareable state. All processing runs client-side via the qrcode package. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
39
lib/qrcode/qrcodeService.ts
Normal file
39
lib/qrcode/qrcodeService.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import QRCode from 'qrcode';
|
||||
import type { ErrorCorrectionLevel } from '@/types/qrcode';
|
||||
|
||||
export async function generateSvg(
|
||||
text: string,
|
||||
errorCorrection: ErrorCorrectionLevel,
|
||||
foregroundColor: string,
|
||||
backgroundColor: string,
|
||||
margin: number,
|
||||
): Promise<string> {
|
||||
return QRCode.toString(text, {
|
||||
type: 'svg',
|
||||
errorCorrectionLevel: errorCorrection,
|
||||
color: {
|
||||
dark: foregroundColor,
|
||||
light: backgroundColor,
|
||||
},
|
||||
margin,
|
||||
});
|
||||
}
|
||||
|
||||
export async function generateDataUrl(
|
||||
text: string,
|
||||
errorCorrection: ErrorCorrectionLevel,
|
||||
foregroundColor: string,
|
||||
backgroundColor: string,
|
||||
margin: number,
|
||||
size: number,
|
||||
): Promise<string> {
|
||||
return QRCode.toDataURL(text, {
|
||||
errorCorrectionLevel: errorCorrection,
|
||||
color: {
|
||||
dark: foregroundColor,
|
||||
light: backgroundColor,
|
||||
},
|
||||
margin,
|
||||
width: size,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user