-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeolapse_sizer.php
More file actions
193 lines (173 loc) · 5.92 KB
/
keolapse_sizer.php
File metadata and controls
193 lines (173 loc) · 5.92 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Keolapse Circle Template</title>
<style>
#flex-container {
display: flex;
justify-content: space-between;
max-width: 1014px;
margin-left: 5px;
margin right: 1014px;
align-items: center;
}
#flex-container p {
margin: 0;
padding: 0 5px;
}
#data {
display: flex; /* Use Flexbox for the data section */
justify-content: space-between;
padding: 0 2px;
}
#data p {
margin: 0;
padding: 0 10px;
margin-right: 20px;
}
#data p:last-child {
margin-right: 0;
}
#container {
position: relative;
width: 1014px;
height: 760px;
border: 2px solid #ccc;
background-size: contain;
background-repeat: no-repeat;
background-position: center;
margin-bottom: 0px;
}
#circle {
position: absolute;
width: 758px;
height: 758px;
border: 1px solid red;
border-radius: 50%;
left: 12.5%;
cursor: move;
}
#resize-handle {
position: absolute;
width: 10px;
height: 10px;
background: red;
bottom: 0;
right: 0;
cursor: se-resize;
}
#data {
font-family: monospace;
font-size: 16px;
}
</style>
</head>
<body>
<h2>Keolapse Circle Template Tool</h2>
<h5>1. Browse to load an image file created by your Allsky camera.<br>
2. Select and drag to position the circle, and use the handle in the right bottom corner to resize. (it's ok if the circle goes outside the border of your image)<br>
3. The data at the top should give you a good starting point for setting up your keolapse circle.</h5>
<div id="flex-container">
<input type="file" id="imageUpload" accept="image/*">
<p id="file-name"></p>
<div id="data">
<p id="radius-factor">Radius Factor: </p>
<p id="x-offset">X Offset: </p>
<p id="y-offset">Y Offset: </p>
</div>
</div>
<br>
<div id="container">
<div id="circle">
<div id="resize-handle"></div>
</div>
</div>
<script>
window.addEventListener('DOMContentLoaded', () => {
const circle = document.getElementById('circle');
const resizeHandle = document.getElementById('resize-handle');
const radiusFactorDisplay = document.getElementById('radius-factor');
const xOffsetDisplay = document.getElementById('x-offset');
const yOffsetDisplay = document.getElementById('y-offset');
const container = document.getElementById('container');
const imageUpload = document.getElementById('imageUpload');
const fileNameDisplay = document.getElementById('file-name');
let isDragging = false;
let isResizing = false;
let offsetX, offsetY;
let originalImageWidth = null;
let originalImageHeight = null;
function updateDataDisplays() {
const circleRect = circle.getBoundingClientRect();
const containerRect = container.getBoundingClientRect();
const radius = circleRect.width / 2;
const radiusFactor = radius / Math.min(containerRect.width, containerRect.height);
const centerX = circleRect.left + radius;
const centerY = circleRect.top + radius;
const xOffset = centerX - (containerRect.left + containerRect.width / 2);
const yOffset = centerY - (containerRect.top + containerRect.height / 2);
let scaledX = xOffset;
let scaledY = yOffset;
if (originalImageWidth && originalImageHeight) {
scaledX = xOffset / containerRect.width * originalImageWidth;
scaledY = yOffset / containerRect.height * originalImageHeight;
}
radiusFactorDisplay.textContent = `Radius Factor: ${radiusFactor.toFixed(2)}`;
xOffsetDisplay.textContent = `X Offset: ${scaledX.toFixed(0)}`;
yOffsetDisplay.textContent = `Y Offset: ${scaledY.toFixed(0)}`;
}
circle.addEventListener('mousedown', (e) => {
if (e.target !== resizeHandle) {
isDragging = true;
offsetX = e.clientX - circle.getBoundingClientRect().left;
offsetY = e.clientY - circle.getBoundingClientRect().top;
}
});
document.addEventListener('mousemove', (e) => {
if (isDragging) {
const containerRect = container.getBoundingClientRect();
let newX = e.clientX - offsetX - containerRect.left;
let newY = e.clientY - offsetY - containerRect.top;
circle.style.left = newX + 'px';
circle.style.top = newY + 'px';
updateDataDisplays();
} else if (isResizing) {
const circleRect = circle.getBoundingClientRect();
const newDiameter = Math.max(50, e.clientX - circleRect.left);
circle.style.width = newDiameter + 'px';
circle.style.height = newDiameter + 'px';
updateDataDisplays();
}
});
document.addEventListener('mouseup', () => {
isDragging = false;
isResizing = false;
});
resizeHandle.addEventListener('mousedown', (e) => {
e.stopPropagation();
isResizing = true;
});
imageUpload.addEventListener('change', (event) => {
const file = event.target.files[0];
if (file && file.type.startsWith('image/')) {
fileNameDisplay.textContent = file.name;
const reader = new FileReader();
reader.onload = function(e) {
const img = new Image();
img.onload = function() {
originalImageWidth = img.width;
originalImageHeight = img.height;
container.style.backgroundImage = `url('${e.target.result}')`;
updateDataDisplays();
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
});
updateDataDisplays();
});
</script>
</body>
</html>