-
Notifications
You must be signed in to change notification settings - Fork 0
/
watermarker.html
212 lines (197 loc) · 7.25 KB
/
watermarker.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Watermarki Nienawiści v1</title>
<style>
body {
font-family: 'Courier New', Courier, monospace;
background-color: black;
color: lime;
margin: 20px;
text-align: center;
}
h1 {
color: lime;
text-transform: uppercase;
}
#canvas {
border: 1px solid lime;
display: block;
margin: 20px auto;
}
.controls {
margin-top: 20px;
}
.controls label {
display: block;
margin: 5px 0;
color: lime;
}
.controls input, .controls button, .controls select {
margin: 5px;
background-color: black;
color: lime;
border: 1px solid lime;
padding: 5px;
font-family: 'Courier New', Courier, monospace;
}
.controls input[type="range"] {
-webkit-appearance: none;
appearance: none;
background: lime;
height: 5px;
border-radius: 5px;
cursor: pointer;
}
.controls input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 15px;
height: 15px;
background: black;
border: 2px solid lime;
border-radius: 50%;
cursor: pointer;
}
.controls input[type="range"]::-moz-range-thumb {
width: 15px;
height: 15px;
background: black;
border: 2px solid lime;
border-radius: 50%;
cursor: pointer;
}
.controls input[type="range"]::-ms-thumb {
width: 15px;
height: 15px;
background: black;
border: 2px solid lime;
border-radius: 50%;
cursor: pointer;
}
.controls button:hover {
background-color: lime;
color: black;
}
</style>
</head>
<body>
<h1>Watermarki Nienawiści v1</h1>
<canvas id="canvas" width="800" height="600"></canvas>
<div class="controls">
<label>
Select an image:
<input type="file" id="imageInput" accept="image/*">
</label>
<label>
Select watermark image:
<input type="file" id="watermarkInput" accept="image/*">
</label>
<label>
Watermark opacity:
<input type="range" id="opacityRange" min="0" max="1" step="0.1" value="0.5">
</label>
<label>
Watermark size (%):
<input type="range" id="sizeRange" min="10" max="200" step="10" value="100">
</label>
<label>
Watermark X Position:
<input type="range" id="xPositionRange" min="0" max="100" step="1" value="50">
</label>
<label>
Watermark Y Position:
<input type="range" id="yPositionRange" min="0" max="100" step="1" value="50">
</label>
<button id="applyWatermark">Apply Watermark</button>
<button id="randomWatermark">Random Watermark</button>
</div>
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const imageInput = document.getElementById('imageInput');
const watermarkInput = document.getElementById('watermarkInput');
const opacityRange = document.getElementById('opacityRange');
const sizeRange = document.getElementById('sizeRange');
const xPositionRange = document.getElementById('xPositionRange');
const yPositionRange = document.getElementById('yPositionRange');
const applyWatermarkButton = document.getElementById('applyWatermark');
const randomWatermarkButton = document.getElementById('randomWatermark');
let mainImage = null;
let watermarkImage = null;
function drawImage() {
if (mainImage) {
canvas.width = mainImage.width;
canvas.height = mainImage.height;
ctx.drawImage(mainImage, 0, 0);
}
}
function applyWatermark() {
if (!mainImage || !watermarkImage) {
alert('Please select both main image and watermark image.');
return;
}
const opacity = parseFloat(opacityRange.value);
const sizePercent = parseInt(sizeRange.value, 10) / 100;
const xPercent = parseInt(xPositionRange.value, 10) / 100;
const yPercent = parseInt(yPositionRange.value, 10) / 100;
const watermarkWidth = watermarkImage.width * sizePercent;
const watermarkHeight = watermarkImage.height * sizePercent;
const x = (canvas.width - watermarkWidth) * xPercent;
const y = (canvas.height - watermarkHeight) * yPercent;
drawImage();
ctx.globalAlpha = opacity;
ctx.drawImage(watermarkImage, x, y, watermarkWidth, watermarkHeight);
ctx.globalAlpha = 1.0; // Reset opacity
}
imageInput.addEventListener('change', (event) => {
const file = event.target.files[0];
if (file) {
const img = new Image();
img.onload = () => {
mainImage = img;
drawImage();
};
img.src = URL.createObjectURL(file);
}
});
watermarkInput.addEventListener('change', (event) => {
const file = event.target.files[0];
if (file) {
const img = new Image();
img.onload = () => {
watermarkImage = img;
};
img.src = URL.createObjectURL(file);
}
});
applyWatermarkButton.addEventListener('click', applyWatermark);
randomWatermarkButton.addEventListener('click', () => {
const folder = './'; // Folder where watermark images are located
fetch(folder)
.then(response => response.text())
.then(text => {
const parser = new DOMParser();
const doc = parser.parseFromString(text, 'text/html');
const images = Array.from(doc.querySelectorAll('a'))
.map(link => link.href)
.filter(href => href.match(/\.(jpg|jpeg|png|gif)$/i));
if (images.length > 0) {
const randomImage = images[Math.floor(Math.random() * images.length)];
const img = new Image();
img.onload = () => {
watermarkImage = img;
applyWatermark();
};
img.src = randomImage;
} else {
alert('No images found in the folder.');
}
})
.catch(error => console.error('Error fetching images:', error));
});
</script>
</body>
</html>