tangled
alpha
login
or
join now
dunkirk.sh
/
img
1
fork
atom
lightweight image tools
1
fork
atom
overview
issues
pulls
pipelines
feat: add optimization
dunkirk.sh
1 month ago
0cff59f0
528a1f3a
verified
This commit was signed with the committer's
known signature
.
dunkirk.sh
SSH Key Fingerprint:
SHA256:DqcG0RXYExE26KiWo3VxJnsxswN1QNfTBvB+bdSpk80=
+93
1 changed file
expand all
collapse all
unified
split
public
index.html
+93
public/index.html
···
135
135
cursor: pointer;
136
136
}
137
137
label { font-size: 0.9rem; color: #666; display: flex; align-items: center; gap: 0.25rem; }
138
138
+
input[type="range"] {
139
139
+
-webkit-appearance: none;
140
140
+
appearance: none;
141
141
+
vertical-align: middle;
142
142
+
margin: 0;
143
143
+
height: 20px;
144
144
+
background: transparent;
145
145
+
}
146
146
+
input[type="range"]::-webkit-slider-runnable-track {
147
147
+
height: 6px;
148
148
+
background: #ccc;
149
149
+
border-radius: 3px;
150
150
+
}
151
151
+
input[type="range"]::-webkit-slider-thumb {
152
152
+
-webkit-appearance: none;
153
153
+
width: 16px;
154
154
+
height: 16px;
155
155
+
background: #666;
156
156
+
border-radius: 50%;
157
157
+
margin-top: -5px;
158
158
+
cursor: pointer;
159
159
+
}
160
160
+
input[type="range"]::-moz-range-track {
161
161
+
height: 6px;
162
162
+
background: #ccc;
163
163
+
border-radius: 3px;
164
164
+
}
165
165
+
input[type="range"]::-moz-range-thumb {
166
166
+
width: 16px;
167
167
+
height: 16px;
168
168
+
background: #666;
169
169
+
border-radius: 50%;
170
170
+
border: none;
171
171
+
cursor: pointer;
172
172
+
}
173
173
+
input[type="number"] { width: 70px; }
138
174
139
175
@media (max-width: 500px) {
140
176
body { margin: 1rem auto; padding: 0.5rem; }
···
173
209
<input type="checkbox" id="showTransparent" checked onchange="updatePreview()">
174
210
Transparent
175
211
</label>
212
212
+
</div>
213
213
+
<div class="toolbar-group">
214
214
+
<label>
215
215
+
Quality:
216
216
+
<input type="range" id="optimizeQuality" min="10" max="100" value="80" style="width: 100px;">
217
217
+
<span id="qualityValue">80%</span>
218
218
+
</label>
219
219
+
<label>
220
220
+
Max:
221
221
+
<input type="number" id="maxDimension" value="2048" min="100" max="8192" style="width: 70px;">
222
222
+
px
223
223
+
</label>
224
224
+
<button onclick="optimizeImage()">Optimize</button>
176
225
</div>
177
226
<div class="toolbar-group">
178
227
<button onclick="downloadImage()">Download</button>
···
641
690
hideError();
642
691
hideStatus();
643
692
fileInput.value = '';
693
693
+
}
694
694
+
695
695
+
// Optimize
696
696
+
document.getElementById('optimizeQuality').oninput = function() {
697
697
+
document.getElementById('qualityValue').textContent = this.value + '%';
698
698
+
};
699
699
+
700
700
+
function optimizeImage() {
701
701
+
if (!currentImage) return;
702
702
+
703
703
+
const quality = document.getElementById('optimizeQuality').value / 100;
704
704
+
const maxDim = parseInt(document.getElementById('maxDimension').value) || 2048;
705
705
+
706
706
+
// Calculate new dimensions (maintain aspect ratio)
707
707
+
let newW = currentImage.width;
708
708
+
let newH = currentImage.height;
709
709
+
710
710
+
if (newW > maxDim || newH > maxDim) {
711
711
+
if (newW > newH) {
712
712
+
newH = Math.round(newH * (maxDim / newW));
713
713
+
newW = maxDim;
714
714
+
} else {
715
715
+
newW = Math.round(newW * (maxDim / newH));
716
716
+
newH = maxDim;
717
717
+
}
718
718
+
}
719
719
+
720
720
+
// Create optimized canvas
721
721
+
const tempCanvas = document.createElement('canvas');
722
722
+
tempCanvas.width = newW;
723
723
+
tempCanvas.height = newH;
724
724
+
const ctx = tempCanvas.getContext('2d');
725
725
+
ctx.drawImage(currentImage, 0, 0, newW, newH);
726
726
+
727
727
+
// Convert to JPEG with quality setting
728
728
+
const optimized = tempCanvas.toDataURL('image/jpeg', quality);
729
729
+
730
730
+
// Load back as current image
731
731
+
const img = new Image();
732
732
+
img.onload = () => {
733
733
+
currentImage = img;
734
734
+
updatePreview();
735
735
+
};
736
736
+
img.src = optimized;
644
737
}
645
738
</script>
646
739
</body>