forked from vishanurag/Canvas-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
196 lines (186 loc) · 8.47 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Creative Canvas Tool</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/5.3.0/css/bootstrap.min.css">
<link rel="stylesheet" href="./src/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="./src/Styles/Style.css">
<link rel="stylesheet" href="./src/Styles/Responsive.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" integrity="sha512-Kc323vGBEqzTmouAECnVceyQqyqdsSiqLQISBL29aUW4U/M7pSPA/gEUZQqv1cwx4OnYxTxve5UMg5GT6L4JJg==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<style>
body {
background-color: #eef1f5;
font-family: 'Arial', sans-serif;
}
.container {
max-width: 1200px;
margin: 0 auto;
color: black;
}
.header {
text-align: center;
margin-bottom: 20px;
}
.canvas-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: #ffffff;
border-radius: 10px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
padding: 20px;
}
#mainCanvas {
max-width: 100%;
height: 400px; /* Set a fixed height */
border: 2px solid #007bff;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
background-color-color: #f0f0f0; /* Default background color */
}
.btn {
margin: 5px;
transition: background-color 0.3s, transform 0.2s;
}
.btn:hover {
background-color: #0056b3;
color: white;
transform: scale(1.05);
}
.btn:active {
transform: scale(0.95);
}
.palette {
margin: 15px 0;
text-align: center;
}
.form-control {
border-radius: 5px;
}
</style>
</head>
<body>
<div class="container-fluid pt-2">
<div class="header">
<h1 class="display-4">Creative Canvas Tool</h1>
<p class="lead">Design and create stunning visuals effortlessly!</p>
</div>
<div class="row">
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Review</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Blog</a>
</li>
</ul>
</div>
<div class="row text-center p-5" style="background-color: cornflowerblue;">
<h2 style="color: white;">Welcome to the Canvas Editor!</h2>
<p style="color: white;">Unleash your creativity with our powerful and easy-to-use canvas editor. <i class="fa-light fa-face-party"></i></p>
</div>
<div class="canvas-container">
<canvas id="mainCanvas"></canvas>
<div class="p-3 bg-light rounded shadow">
<form id="userForm" class="d-flex flex-column">
<div class="d-flex gap-3 mb-2">
<label for="textSize" class="text-dark">Size:</label>
<select name="tSize" class="form-select" id="textSize">
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
</select>
<label for="colorPicker" class="text-dark">Color:</label>
<input type="color" name="colorPicker" class="form-control" id="colorPicker">
</div>
<div class="d-flex row gap-3">
<div class="col-sm-6">
<label for="bgImageUpload" class="text-dark">Background Image:</label>
<input type="file" id="bgImageUpload" accept="image/*">
</div>
<div class="col-sm-6">
<label for="bgColorPicker" class="text-dark">Background Color:</label>
<input type="color" id="bgColorPicker" class="form-control" value="#f0f0f0">
</div>
</div>
<div class="d-md-flex justify-content-evenly gap-1">
<button class="btn btn-primary" id="capital">A</button>
<button class="btn btn-primary" id="small">a</button>
<button class="btn btn-primary" id="bold">B</button>
<button class="btn btn-primary" id="italic">I</button>
</div>
<p class="text-center">Shape Palette</p>
<div class="palette">
<button id="rectangleBtn" class="btn btn-success">Rectangle</button>
<button id="circleBtn" class="btn btn-success">Circle</button>
<button id="lineBtn" class="btn btn-success">Line</button>
</div>
<div class="d-md-flex justify-content-center gap-1">
<input type="text" placeholder="Enter Text" name="textData" id="textData" class="form-control mw-100 w-75 mb-3">
<button type="button" class="btn btn-primary" id="save">Save</button>
<button type="button" class="btn btn-danger" id="clear">Clear</button>
<button type="button" class="btn btn-success" id="download" title="Download">Download</button>
</div>
</form>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/gsap.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script>
const canvas = document.getElementById('mainCanvas');
const ctx = canvas.getContext('2d');
// Set canvas size
canvas.width = 800;
canvas.height = 400;
let history = [];
let redoStack = [];
function saveState() {
history.push(ctx.getImageData(0, 0, canvas.width, canvas.height));
redoStack = []; // Clear redo stack on new action
if (history.length > 10) history.shift(); // Limit history size
}
function setCanvasBackgroundColor(color) {
ctx.fillStyle = color;
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
// Set initial background color
const initialBgColor = document.getElementById('bgColorPicker').value;
setCanvasBackgroundColor(initialBgColor);
// Background color change
document.getElementById('bgColorPicker').addEventListener('input', function() {
const color = this.value;
setCanvasBackgroundColor(color);
});
// Add text functionality
document.getElementById('addText').addEventListener('click', function() {
const textData = document.getElementById('textData').value;
const textSize = document.getElementById('textSize').value;
const textColor = document.getElementById('colorPicker').value;
if (textData) {
saveState(); // Save state before adding text
ctx.fillStyle = textColor;
ctx.font = `${textSize}px Arial`;
ctx.fillText(textData, 50, 50); // Set text position
document.getElementById('textData').value = ''; // Clear input field
} else {
alert('Please enter some text!');
}
});
// Upload image functionality
document.getElementById('uploadImage').addEventListener('click', function() {
const input = document.createElement('input');
input.type = 'file';
input.accept = 'image/*';
input.onchange = e => {
const file = e.target.files[0];
const reader = new File