Spaces:
Running
Running
0.2.1
Browse filesMerge pull request #2 from BlueSkyXN/claude/heif-lossless-compression-011CUwQdCnFy6RWEBZpBqz5Y
main.py
CHANGED
|
@@ -296,12 +296,12 @@ HTML_UPLOAD_PAGE = """
|
|
| 296 |
<div class="form-group">
|
| 297 |
<label for="target_format">目标格式</label>
|
| 298 |
<select name="target_format" id="target_format" required>
|
| 299 |
-
<option value="webp"
|
| 300 |
<option value="avif">AVIF - 最新一代格式</option>
|
| 301 |
<option value="jpeg">JPEG - 经典有损格式</option>
|
| 302 |
<option value="png">PNG - 无损格式</option>
|
| 303 |
<option value="gif">GIF - 动画格式</option>
|
| 304 |
-
<option value="heif">HEIF - 高效图像格式</option>
|
| 305 |
</select>
|
| 306 |
</div>
|
| 307 |
|
|
@@ -309,11 +309,11 @@ HTML_UPLOAD_PAGE = """
|
|
| 309 |
<label>转换模式</label>
|
| 310 |
<div class="radio-group">
|
| 311 |
<label class="radio-label">
|
| 312 |
-
<input type="radio" name="mode" value="lossy"
|
| 313 |
有损压缩 (更小体积)
|
| 314 |
</label>
|
| 315 |
<label class="radio-label">
|
| 316 |
-
<input type="radio" name="mode" value="lossless">
|
| 317 |
无损压缩 (保持质量)
|
| 318 |
</label>
|
| 319 |
</div>
|
|
@@ -322,11 +322,11 @@ HTML_UPLOAD_PAGE = """
|
|
| 322 |
<div class="form-group">
|
| 323 |
<label for="setting">质量参数</label>
|
| 324 |
<div class="slider-container">
|
| 325 |
-
<input type="range" name="setting" id="setting" min="0" max="100" value="
|
| 326 |
-
<span class="slider-value" id="settingValue">
|
| 327 |
</div>
|
| 328 |
<div class="param-hint" id="paramHint">
|
| 329 |
-
|
| 330 |
</div>
|
| 331 |
</div>
|
| 332 |
|
|
@@ -381,7 +381,19 @@ HTML_UPLOAD_PAGE = """
|
|
| 381 |
}
|
| 382 |
|
| 383 |
slider.addEventListener('input', updateHint);
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
|
| 386 |
// 表单提交处理
|
| 387 |
const form = document.getElementById('uploadForm');
|
|
@@ -688,9 +700,9 @@ async def _perform_conversion(
|
|
| 688 |
async def upload_convert(
|
| 689 |
background_tasks: BackgroundTasks,
|
| 690 |
file: UploadFile = File(..., description="要转换的图像文件"),
|
| 691 |
-
target_format: str = Form("
|
| 692 |
-
mode: str = Form("
|
| 693 |
-
setting: int = Form(
|
| 694 |
):
|
| 695 |
"""
|
| 696 |
通过HTML表单上传并转换图像。
|
|
|
|
| 296 |
<div class="form-group">
|
| 297 |
<label for="target_format">目标格式</label>
|
| 298 |
<select name="target_format" id="target_format" required>
|
| 299 |
+
<option value="webp">WebP - 现代高效格式</option>
|
| 300 |
<option value="avif">AVIF - 最新一代格式</option>
|
| 301 |
<option value="jpeg">JPEG - 经典有损格式</option>
|
| 302 |
<option value="png">PNG - 无损格式</option>
|
| 303 |
<option value="gif">GIF - 动画格式</option>
|
| 304 |
+
<option value="heif" selected>HEIF - 高效图像格式</option>
|
| 305 |
</select>
|
| 306 |
</div>
|
| 307 |
|
|
|
|
| 309 |
<label>转换模式</label>
|
| 310 |
<div class="radio-group">
|
| 311 |
<label class="radio-label">
|
| 312 |
+
<input type="radio" name="mode" value="lossy">
|
| 313 |
有损压缩 (更小体积)
|
| 314 |
</label>
|
| 315 |
<label class="radio-label">
|
| 316 |
+
<input type="radio" name="mode" value="lossless" checked>
|
| 317 |
无损压缩 (保持质量)
|
| 318 |
</label>
|
| 319 |
</div>
|
|
|
|
| 322 |
<div class="form-group">
|
| 323 |
<label for="setting">质量参数</label>
|
| 324 |
<div class="slider-container">
|
| 325 |
+
<input type="range" name="setting" id="setting" min="0" max="100" value="0">
|
| 326 |
+
<span class="slider-value" id="settingValue">0</span>
|
| 327 |
</div>
|
| 328 |
<div class="param-hint" id="paramHint">
|
| 329 |
+
压缩速度: 0 - 最慢/最佳压缩 (0=最慢/最佳,100=最快/最差)
|
| 330 |
</div>
|
| 331 |
</div>
|
| 332 |
|
|
|
|
| 381 |
}
|
| 382 |
|
| 383 |
slider.addEventListener('input', updateHint);
|
| 384 |
+
|
| 385 |
+
// 当模式切换时,自动调整质量值
|
| 386 |
+
modeRadios.forEach(radio => radio.addEventListener('change', function() {
|
| 387 |
+
const mode = document.querySelector('input[name="mode"]:checked').value;
|
| 388 |
+
if (mode === 'lossless') {
|
| 389 |
+
// 无损模式:默认最佳质量(0=最慢/最佳压缩)
|
| 390 |
+
slider.value = 0;
|
| 391 |
+
} else {
|
| 392 |
+
// 有损模式:默认中等质量(50=中等质量)
|
| 393 |
+
slider.value = 50;
|
| 394 |
+
}
|
| 395 |
+
updateHint();
|
| 396 |
+
}));
|
| 397 |
|
| 398 |
// 表单提交处理
|
| 399 |
const form = document.getElementById('uploadForm');
|
|
|
|
| 700 |
async def upload_convert(
|
| 701 |
background_tasks: BackgroundTasks,
|
| 702 |
file: UploadFile = File(..., description="要转换的图像文件"),
|
| 703 |
+
target_format: str = Form("heif", description="目标格式"),
|
| 704 |
+
mode: str = Form("lossless", description="转换模式"),
|
| 705 |
+
setting: int = Form(0, ge=0, le=100, description="质量参数")
|
| 706 |
):
|
| 707 |
"""
|
| 708 |
通过HTML表单上传并转换图像。
|