-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
227 lines (204 loc) · 7.79 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<!DOCTYPE html>
<html>
<head>
<title>JPG to PNG Image Converter</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
#downloadButton {
display: none;
}
body {
background-color: #f8f9fa;
color: #333;
font-family: Arial, sans-serif;
}
.container {
max-width: 500px;
margin: 0 auto;
}
h1 {
font-size: 24px;
margin-bottom: 20px;
text-align: center;
}
p {
font-size: 18px;
margin-bottom: 10px;
}
input[type="file"] {
margin-bottom: 15px;
}
.form-check-label {
font-weight: normal;
}
#outputContainer {
text-align: center;
margin-top: 20px;
}
#outputContainer img {
max-width: 100%;
}
/* Additional custom styles */
.form-check {
margin-bottom: 10px;
}
.form-row.ml-3 {
margin-left: 20px;
}
.btn-primary {
display: block;
margin-top: 30px;
width: 100%;
}
</style>
</head>
<body>
<div class="container mt-5">
<h1>JPG to PNG Image Converter</h1>
<p>Select a JPG image to convert:</p>
<input type="file" id="imageInput" accept=".jpg, .jpeg" class="form-control-file">
<div class="form-group mt-3">
<label for="qualitySlider">PNG Quality:</label>
<input type="range" id="qualitySlider" min="0" max="1" step="0.1" value="0.8" class="form-control-range">
<span id="qualityValue">0.8</span>
</div>
<div class="form-check">
<input type="checkbox" id="grayscaleCheckbox" class="form-check-input">
<label for="grayscaleCheckbox" class="form-check-label">Convert to Grayscale</label>
</div>
<div class="form-check">
<input type="checkbox" id="resizeCheckbox" class="form-check-input">
<label for="resizeCheckbox" class="form-check-label">Resize Image</label>
<div class="form-row ml-3">
<div class="form-group col-md-4">
<label for="widthInput">Width:</label>
<input type="number" id="widthInput" class="form-control" min="1">
</div>
<div class="form-group col-md-4">
<label for="heightInput">Height:</label>
<input type="number" id="heightInput" class="form-control" min="1">
</div>
</div>
</div>
<div class="form-check">
<input type="checkbox" id="watermarkCheckbox" class="form-check-input">
<label for="watermarkCheckbox" class="form-check-label">Add Watermark</label>
<div class="form-row ml-3">
<div class="form-group col-md-8">
<label for="watermarkText">Watermark Text:</label>
<input type="text" id="watermarkText" class="form-control">
</div>
<div class="form-group col-md-4">
<label for="watermarkColor">Watermark Color:</label>
<input type="color" id="watermarkColor" class="form-control">
</div>
</div>
</div>
<div class="form-check">
<input type="checkbox" id="rotateCheckbox" class="form-check-input">
<label for="rotateCheckbox" class="form-check-label">Rotate Image</label>
<div class="form-row ml-3">
<div class="form-group col-md-4">
<label for="rotationAngle">Rotation Angle:</label>
<input type="number" id="rotationAngle" class="form-control" min="0" max="360" step="1">
</div>
</div>
</div>
<div class="form-check">
<input type="checkbox" id="cropCheckbox" class="form-check-input">
<label for="cropCheckbox" class="form-check-label">Crop Image</label>
<div class="form-row ml-3">
<div class="form-group col-md-4">
<label for="cropX">X:</label>
<input type="number" id="cropX" class="form-control" min="0">
</div>
<div class="form-group col-md-4">
<label for="cropY">Y:</label>
<input type="number" id="cropY" class="form-control" min="0">
</div>
<div class="form-group col-md-4">
<label for="cropSize">Size:</label>
<input type="number" id="cropSize" class="form-control" min="1">
</div>
</div>
</div>
<button id="convertButton" class="btn btn-primary">Convert</button>
<div id="outputContainer">
<h2>Converted Image:</h2>
<img id="outputImage" class="mt-3">
<a id="downloadButton" class="btn btn-primary mt-3" download>Download</a>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$("#convertButton").click(function() {
var fileInput = document.getElementById("imageInput");
var file = fileInput.files[0];
if (file) {
var quality = document.getElementById("qualitySlider").value;
var grayscale = document.getElementById("grayscaleCheckbox").checked;
var resize = document.getElementById("resizeCheckbox").checked;
var width = document.getElementById("widthInput").value;
var height = document.getElementById("heightInput").value;
var watermark = document.getElementById("watermarkCheckbox").checked;
var watermarkText = document.getElementById("watermarkText").value;
var watermarkColor = document.getElementById("watermarkColor").value;
var rotate = document.getElementById("rotateCheckbox").checked;
var rotationAngle = document.getElementById("rotationAngle").value;
var crop = document.getElementById("cropCheckbox").checked;
var cropX = document.getElementById("cropX").value;
var cropY = document.getElementById("cropY").value;
var cropSize = document.getElementById("cropSize").value;
var reader = new FileReader();
reader.onload = function(e) {
var img = document.createElement("img");
img.onload = function() {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
var outputImage = document.getElementById("outputImage");
if (grayscale) {
ctx.filter = "grayscale(100%)";
}
var targetWidth = resize ? width : img.width;
var targetHeight = resize ? height : img.height;
canvas.width = targetWidth;
canvas.height = targetHeight;
if (rotate) {
var angle = rotationAngle * (Math.PI / 180);
ctx.translate(canvas.width / 2, canvas.height / 2);
ctx.rotate(angle);
ctx.drawImage(img, -canvas.width / 2, -canvas.height / 2, canvas.width, canvas.height);
} else {
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
}
if (crop) {
var size = Math.min(cropSize, canvas.width, canvas.height);
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(img, cropX, cropY, size, size, 0, 0, canvas.width, canvas.height);
}
if (watermark) {
ctx.fillStyle = watermarkColor;
ctx.font = "30px Arial";
ctx.fillText(watermarkText, 10, canvas.height - 10);
}
var convertedImageURL = canvas.toDataURL("image/png");
outputImage.src = convertedImageURL;
// Show the download button
var downloadButton = document.getElementById("downloadButton");
downloadButton.href = convertedImageURL;
downloadButton.style.display = "block";
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
});
$("#qualitySlider").on("input", function() {
var value = $(this).val();
$("#qualityValue").text(value);
});
});
</script>
</body>
</html>