copy to word combined
This commit is contained in:
41
QRCode.html
41
QRCode.html
@ -109,6 +109,11 @@
|
|||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Hidden canvas for combining QR and label */
|
||||||
|
#combinedCanvas {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 600px) {
|
@media (max-width: 600px) {
|
||||||
body {
|
body {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
@ -142,6 +147,9 @@
|
|||||||
<div id="qrcode"></div>
|
<div id="qrcode"></div>
|
||||||
<div id="qrLabel"></div>
|
<div id="qrLabel"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Hidden canvas for combining QR and label -->
|
||||||
|
<canvas id="combinedCanvas"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -180,14 +188,37 @@
|
|||||||
async function copyQRToClipboard() {
|
async function copyQRToClipboard() {
|
||||||
try {
|
try {
|
||||||
const qrImage = document.querySelector('#qrcode img');
|
const qrImage = document.querySelector('#qrcode img');
|
||||||
|
const label = document.getElementById('qrLabel').textContent;
|
||||||
if (!qrImage) return;
|
if (!qrImage) return;
|
||||||
|
|
||||||
// Create a canvas and draw the QR code on it
|
// Create a canvas for the combined image
|
||||||
const canvas = document.createElement('canvas');
|
const canvas = document.getElementById('combinedCanvas');
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
canvas.width = qrImage.width;
|
|
||||||
canvas.height = qrImage.height;
|
// Set canvas size to accommodate both QR code and label
|
||||||
ctx.drawImage(qrImage, 0, 0);
|
const padding = 20;
|
||||||
|
const fontSize = 16;
|
||||||
|
ctx.font = `bold ${fontSize}px Arial`;
|
||||||
|
const labelMetrics = ctx.measureText(label);
|
||||||
|
|
||||||
|
canvas.width = Math.max(qrImage.width, labelMetrics.width);
|
||||||
|
canvas.height = qrImage.height + (label ? fontSize + padding : 0);
|
||||||
|
|
||||||
|
// Fill with white background
|
||||||
|
ctx.fillStyle = '#ffffff';
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
|
// Draw QR code
|
||||||
|
const qrX = (canvas.width - qrImage.width) / 2;
|
||||||
|
ctx.drawImage(qrImage, qrX, 0);
|
||||||
|
|
||||||
|
// Draw label if it exists
|
||||||
|
if (label) {
|
||||||
|
ctx.fillStyle = '#000000';
|
||||||
|
ctx.font = `bold ${fontSize}px Arial`;
|
||||||
|
ctx.textAlign = 'center';
|
||||||
|
ctx.fillText(label, canvas.width / 2, qrImage.height + fontSize);
|
||||||
|
}
|
||||||
|
|
||||||
// Convert canvas to blob
|
// Convert canvas to blob
|
||||||
const blob = await new Promise(resolve => canvas.toBlob(resolve, 'image/png'));
|
const blob = await new Promise(resolve => canvas.toBlob(resolve, 'image/png'));
|
||||||
|
Reference in New Issue
Block a user