image-optimizer-webui 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- image_optimizer/__init__.py +3 -0
- image_optimizer/__main__.py +2 -0
- image_optimizer/binaries.py +430 -0
- image_optimizer/cache.py +362 -0
- image_optimizer/main.py +3929 -0
- image_optimizer/models.py +147 -0
- image_optimizer/optimizer.py +1378 -0
- image_optimizer/templates/favicon.ico +0 -0
- image_optimizer/templates/index.html +3066 -0
- image_optimizer/watcher.py +180 -0
- image_optimizer_webui-1.1.0.dist-info/METADATA +388 -0
- image_optimizer_webui-1.1.0.dist-info/RECORD +16 -0
- image_optimizer_webui-1.1.0.dist-info/WHEEL +5 -0
- image_optimizer_webui-1.1.0.dist-info/entry_points.txt +2 -0
- image_optimizer_webui-1.1.0.dist-info/licenses/LICENSE +21 -0
- image_optimizer_webui-1.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ScanRequest(BaseModel):
|
|
9
|
+
directory: str
|
|
10
|
+
recursive: bool = True
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class OptimizeRequest(BaseModel):
|
|
14
|
+
# None = "no filter, process everything"; [] = "process nothing" (all files
|
|
15
|
+
# were deselected). These used to be conflated because Python treats an
|
|
16
|
+
# empty list as falsy — keep them distinct.
|
|
17
|
+
file_ids: Optional[list[str]] = None
|
|
18
|
+
quality: str = "medium"
|
|
19
|
+
max_width: int = 0
|
|
20
|
+
output_format: str = "png"
|
|
21
|
+
output_dir: str = ""
|
|
22
|
+
# "standard" = pngquant + oxipng (current default behavior)
|
|
23
|
+
# "lossless" = oxipng only, no color quantization
|
|
24
|
+
# "resize_only" = no color quantization, relies on max_width for savings
|
|
25
|
+
compression_mode: str = "standard"
|
|
26
|
+
# Hex colors (e.g. "#2ecc71") to prioritize keeping in the palette when
|
|
27
|
+
# compression_mode == "standard". Best-effort, not a hard guarantee.
|
|
28
|
+
protected_colors: list[str] = []
|
|
29
|
+
# Whether pngquant should dither (Floyd-Steinberg). Only relevant when
|
|
30
|
+
# compression_mode == "standard".
|
|
31
|
+
dithering: bool = True
|
|
32
|
+
# Retry mode: re-run only the given file_ids (the previously-failed ones)
|
|
33
|
+
# without wiping the output dir or discarding earlier successful results.
|
|
34
|
+
# Default False keeps the normal "fresh full run" behavior (clears output,
|
|
35
|
+
# replaces results) that every existing caller/test relies on.
|
|
36
|
+
retry: bool = False
|
|
37
|
+
# Skip files whose optimized output already exists in output_dir: instead
|
|
38
|
+
# of recompressing, reuse the existing file (copied back into ws/output so
|
|
39
|
+
# Compare/preview and the download ZIP still work). Only meaningful with a
|
|
40
|
+
# persistent output_dir set; a no-op otherwise (the temp workspace starts
|
|
41
|
+
# empty each run). Default False keeps the normal recompress-everything run.
|
|
42
|
+
skip_existing: bool = False
|
|
43
|
+
# Retain a curated EXIF subset (camera make/model, date, exposure) in the
|
|
44
|
+
# output while dropping Orientation (already baked into pixels by
|
|
45
|
+
# exif_transpose — re-writing it would double-rotate), GPS (privacy), and
|
|
46
|
+
# MakerNote (bulk). Default False preserves the historical strip-everything
|
|
47
|
+
# behavior (pngquant --strip / oxipng --strip safe / WebP with no exif=).
|
|
48
|
+
keep_exif: bool = False
|
|
49
|
+
# Per-file parameter override: {file_id: {field: value, ...}}. Only the
|
|
50
|
+
# listed fields override the top-level defaults for that one file; every
|
|
51
|
+
# other field falls back to the top-level value. Only file_ids the user
|
|
52
|
+
# manually expanded "advanced settings" on appear here — the common case
|
|
53
|
+
# (one global setting) sends an empty dict. Field names are fixed (see
|
|
54
|
+
# OVERRIDEABLE_FIELDS in main.py) so the request shape can't drift between
|
|
55
|
+
# frontend and backend; unknown fields are rejected with 400.
|
|
56
|
+
overrides: dict[str, dict] = {}
|
|
57
|
+
# Resume a previously interrupted batch. When True, the backend loads
|
|
58
|
+
# ~/.image-optimizer/batch_state.json, reconstructs state.files from it,
|
|
59
|
+
# and only processes files whose status is "pending" or "failed".
|
|
60
|
+
# Input/output dirs and compression params must match the saved batch.
|
|
61
|
+
resume: bool = False
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class FileInfo(BaseModel):
|
|
65
|
+
"""Shape of one entry in AppState.files / the /api/scan|upload payloads.
|
|
66
|
+
Documentation-only — those dicts are built by hand for flexibility, but
|
|
67
|
+
this model is the reference for what consumers can rely on."""
|
|
68
|
+
id: str
|
|
69
|
+
name: str
|
|
70
|
+
path: str
|
|
71
|
+
size: int
|
|
72
|
+
thumbnail: str
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class ResultInfo(BaseModel):
|
|
76
|
+
"""Shape of one entry in AppState.results / the /api/progress payload.
|
|
77
|
+
Documentation-only, same reasoning as FileInfo."""
|
|
78
|
+
id: str
|
|
79
|
+
name: str
|
|
80
|
+
original_path: str
|
|
81
|
+
# Output path relative to the workspace output dir — may differ from
|
|
82
|
+
# name+suffix when a filename collision was disambiguated.
|
|
83
|
+
output_name: Optional[str] = None
|
|
84
|
+
original_size: int
|
|
85
|
+
compressed_size: int
|
|
86
|
+
savings: int
|
|
87
|
+
savings_percent: float
|
|
88
|
+
success: bool
|
|
89
|
+
error: Optional[str] = None
|
|
90
|
+
warning: Optional[str] = None
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class RecentRemoveRequest(BaseModel):
|
|
94
|
+
key: str
|
|
95
|
+
value: str
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class RecentClearRequest(BaseModel):
|
|
99
|
+
key: str
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class RevealRequest(BaseModel):
|
|
103
|
+
"""Open the OS file explorer. An empty path reveals the run's output
|
|
104
|
+
folder itself (recorded server-side in state.output_dir, nothing
|
|
105
|
+
client-supplied); a non-empty path must be one of the current
|
|
106
|
+
session's own recorded final_output_path values — see /api/reveal
|
|
107
|
+
for why."""
|
|
108
|
+
path: str = ""
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class PreviewRequest(BaseModel):
|
|
112
|
+
"""Single-file pre-compression dry run. Carries the same compression
|
|
113
|
+
parameters as OptimizeRequest for one file, but no batch/output
|
|
114
|
+
controls (no output_dir, skip_existing, retry, file_ids list) — a
|
|
115
|
+
preview never persists anything."""
|
|
116
|
+
file_id: str
|
|
117
|
+
quality: str = "medium"
|
|
118
|
+
max_width: int = 0
|
|
119
|
+
output_format: str = "png"
|
|
120
|
+
compression_mode: str = "standard"
|
|
121
|
+
protected_colors: list[str] = []
|
|
122
|
+
dithering: bool = True
|
|
123
|
+
keep_exif: bool = False
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class WatchRequest(BaseModel):
|
|
127
|
+
"""Parameters for Watch mode: watch a directory and auto-optimize every
|
|
128
|
+
image that appears (or changes) in it, writing results into output_dir.
|
|
129
|
+
Carries the same compression parameters as OptimizeRequest, minus the
|
|
130
|
+
batch-specific controls (file_ids / retry / skip_existing / overrides) —
|
|
131
|
+
Watch uses one global setting set for everything it picks up.
|
|
132
|
+
|
|
133
|
+
output_dir is required: Watch has no temp-workspace/ZIP flow, it is
|
|
134
|
+
inherently "optimize into a persistent folder"."""
|
|
135
|
+
directory: str
|
|
136
|
+
recursive: bool = True
|
|
137
|
+
# Optimize files already present when watching starts, not just ones
|
|
138
|
+
# that appear afterwards.
|
|
139
|
+
process_existing: bool = False
|
|
140
|
+
quality: str = "medium"
|
|
141
|
+
max_width: int = 0
|
|
142
|
+
output_format: str = "png"
|
|
143
|
+
compression_mode: str = "standard"
|
|
144
|
+
protected_colors: list[str] = []
|
|
145
|
+
dithering: bool = True
|
|
146
|
+
keep_exif: bool = False
|
|
147
|
+
output_dir: str = ""
|