Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created the signature app #1624

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions projects/SignatureMakingSite/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Signature App</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="controls">
<label for="textColor">Text Color</label>
<input type="color" id="textColor" value="#000000">
<label for="canvasBgColor">Canvas Background</label>
<input type="color" id="canvasBgColor" value="#FFFFFF">
<label for="fontSize">Font Size</label>
<select id="fontSize">
<option value="1px">1px</option>
<option value="2px">2px</option>
<option value="3px">3px</option>
<option value="4px">4px</option>
<option value="5px">5px</option>
</select>
</div>
<div class="signature-container">
<div class="signature-area">
<canvas id="signatureCanvas" width="700" height="400"></canvas>
</div>
<div class="gif-container">
<img src="https://media.tenor.com/yCFHzEvKa9MAAAAi/hello.gif" alt="Animated GIF">
</div>
</div>
<div class="buttons">
<button id="clearBtn">Clear</button>
<button id="saveBtn">Save & Download</button>
<button id="retrieveBtn">Retrieve Saved Signature</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
68 changes: 68 additions & 0 deletions projects/SignatureMakingSite/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const canvas = document.getElementById('signatureCanvas');
const ctx = canvas.getContext('2d');
let painting = false;

const startPosition = (e) => {
painting = true;
draw(e);
};

const finishedPosition = () => {
painting = false;
ctx.beginPath();
};

const draw = (e) => {
if (!painting) return; // Only draw when the mouse is pressed down
ctx.lineWidth = document.getElementById('fontSize').value;
ctx.lineCap = 'round';
ctx.strokeStyle = document.getElementById('textColor').value;

// Draw line
ctx.lineTo(e.clientX - canvas.offsetLeft, e.clientY - canvas.offsetTop);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(e.clientX - canvas.offsetLeft, e.clientY - canvas.offsetTop);
};

// Mouse events
canvas.addEventListener('mousedown', startPosition);
canvas.addEventListener('mouseup', finishedPosition);
canvas.addEventListener('mousemove', draw);
canvas.addEventListener('mouseleave', finishedPosition); // Stop drawing when leaving canvas
canvas.addEventListener('mouseenter', () => {
if (painting) {
draw(event); // Draw if painting is true when mouse enters
}
});

// Button events
document.getElementById('clearBtn').addEventListener('click', () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
});

document.getElementById('saveBtn').addEventListener('click', () => {
const dataURL = canvas.toDataURL('image/png');
const link = document.createElement('a');
link.href = dataURL;
link.download = 'signature.png';
link.click();
});

document.getElementById('retrieveBtn').addEventListener('click', () => {
const savedImage = localStorage.getItem('savedSignature');
if (savedImage) {
const img = new Image();
img.src = savedImage;
img.onload = () => {
ctx.drawImage(img, 0, 0);
};
} else {
alert('No saved signature found!');
}
});

// Change canvas background color
document.getElementById('canvasBgColor').addEventListener('change', (e) => {
canvas.style.backgroundColor = e.target.value;
});
86 changes: 86 additions & 0 deletions projects/SignatureMakingSite/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
body {
background-image: url('https://wallpapers.com/images/hd/minimalist-vintage-1920-x-1080-wallpaper-h18al5zfcc6wozfv.jpg');
background-size: cover;
background-position: center;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
color: #fff;
}

.container {
background: rgba(0, 0, 0, 0.7);
padding: 20px;
border-radius: 10px;
text-align: center;
}

.controls {
display: flex;
justify-content: space-around;
margin-bottom: 20px;
}

.controls label, .controls input, .controls select {
margin-right: 10px;
}

.signature-container {
display: flex;
justify-content: center;
align-items: center;
}

.signature-area {
border: 2px solid #fff;
background-color: #fff;
margin-right: 20px;
}

#signatureCanvas {
background-color: #fff;
}

.gif-container {
display: flex;
justify-content: center;
align-items: center;
}

.gif-container img {
width: 100px;
height: auto;
}

.buttons {
display: flex;
justify-content: space-around;
margin-top: 20px;
}

button {
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}

#clearBtn {
background-color: #ff4f4f;
color: #fff;
}

#saveBtn {
background-color: #4caf50;
color: #fff;
}

#retrieveBtn {
background-color: #ffa500;
color: #fff;
}
Loading