webp-tui 2.0.1__tar.gz
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.
- webp_tui-2.0.1/LICENSE +21 -0
- webp_tui-2.0.1/PKG-INFO +199 -0
- webp_tui-2.0.1/README.md +147 -0
- webp_tui-2.0.1/pyproject.toml +49 -0
- webp_tui-2.0.1/setup.cfg +4 -0
- webp_tui-2.0.1/tests/test_converter.py +251 -0
- webp_tui-2.0.1/tests/test_tui.py +81 -0
- webp_tui-2.0.1/webp_converter/__init__.py +3 -0
- webp_tui-2.0.1/webp_converter/cli.py +197 -0
- webp_tui-2.0.1/webp_converter/config.py +160 -0
- webp_tui-2.0.1/webp_converter/core.py +404 -0
- webp_tui-2.0.1/webp_converter/main.py +39 -0
- webp_tui-2.0.1/webp_converter/tui.py +575 -0
- webp_tui-2.0.1/webp_tui.egg-info/PKG-INFO +199 -0
- webp_tui-2.0.1/webp_tui.egg-info/SOURCES.txt +17 -0
- webp_tui-2.0.1/webp_tui.egg-info/dependency_links.txt +1 -0
- webp_tui-2.0.1/webp_tui.egg-info/entry_points.txt +2 -0
- webp_tui-2.0.1/webp_tui.egg-info/requires.txt +5 -0
- webp_tui-2.0.1/webp_tui.egg-info/top_level.txt +1 -0
webp_tui-2.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 RenX86
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
webp_tui-2.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: webp-tui
|
|
3
|
+
Version: 2.0.1
|
|
4
|
+
Summary: Batch image-to-WebP converter with an interactive terminal UI (TUI) and CLI for Windows
|
|
5
|
+
Author: RenX86
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 RenX86
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/RenX86/WebP-Image-Converter
|
|
29
|
+
Project-URL: Repository, https://github.com/RenX86/WebP-Image-Converter
|
|
30
|
+
Project-URL: Issues, https://github.com/RenX86/WebP-Image-Converter/issues
|
|
31
|
+
Keywords: webp,image,converter,tui,textual,pillow,cli
|
|
32
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
33
|
+
Classifier: Environment :: Console
|
|
34
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
43
|
+
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
|
|
44
|
+
Requires-Python: >=3.9
|
|
45
|
+
Description-Content-Type: text/markdown
|
|
46
|
+
License-File: LICENSE
|
|
47
|
+
Requires-Dist: Pillow>=9.0.0
|
|
48
|
+
Requires-Dist: textual>=0.80.0
|
|
49
|
+
Provides-Extra: dev
|
|
50
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# WebP Image Converter
|
|
54
|
+
|
|
55
|
+
A fast, safe batch image-to-WebP converter for Windows with an interactive **Terminal UI (TUI)** and a scriptable **CLI**, powered purely by Pillow (`libwebp`) — no external binaries required.
|
|
56
|
+
|
|
57
|
+
> Looking for v1.0 (Flask Web UI, `cwebp`/`ExifTool`, and Stable Diffusion metadata)? Check out the `v1.0.0` git tag.
|
|
58
|
+
|
|
59
|
+
## Features
|
|
60
|
+
|
|
61
|
+
- **Interactive Terminal UI (`webp-converter`)**: Browse folders, preview file counts and sizes, adjust settings, watch live per-file progress and space saved, or cancel mid-batch.
|
|
62
|
+
- **Scriptable CLI**: Pass a folder path and flags for automated/batch workflows with clean exit codes (`0` success, `1` partial failure/skip, `2` fatal error).
|
|
63
|
+
- **Pure Python / Pillow**: Converts JPG, JPEG, PNG, TIFF/TIF, BMP, and GIF (including **animated GIFs** to animated WebP) in-process — no `cwebp.exe` or `ExifTool` setup needed.
|
|
64
|
+
- **Lossy or pixel-exact lossless**: Configurable quality (`0–100`) and compression effort (`method 0–6`), or lossless encoding with exact RGB preservation under transparency.
|
|
65
|
+
- **Metadata preservation**: Carries over EXIF tags, ICC color profiles, XMP packets, and standard PNG/GIF/BMP text comments (`Author`, `Software`, `Comment`, `Creation Time`), and automatically applies EXIF orientation to static images.
|
|
66
|
+
- **Safe by default**:
|
|
67
|
+
- Original files are kept unless `--delete-originals` (or the TUI toggle) is enabled.
|
|
68
|
+
- Files are written atomically via temp files and originals are only removed after verified output.
|
|
69
|
+
- Never overwrites silently: `photo.jpg` + `photo.png` become `photo_jpg.webp` + `photo_png.webp`, and existing `.webp` files are left alone unless `--overwrite` is set.
|
|
70
|
+
|
|
71
|
+
## Requirements
|
|
72
|
+
|
|
73
|
+
- Windows 10 / 11 (Windows Terminal recommended for the TUI)
|
|
74
|
+
- Python 3.9 or higher
|
|
75
|
+
|
|
76
|
+
## Installation
|
|
77
|
+
|
|
78
|
+
### Recommended: install globally from PyPI
|
|
79
|
+
|
|
80
|
+
Using `uv` or `pipx` (adds `webp-converter` to your `PATH` in an isolated environment):
|
|
81
|
+
|
|
82
|
+
```powershell
|
|
83
|
+
uv tool install webp-tui
|
|
84
|
+
# or
|
|
85
|
+
pipx install webp-tui
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Or with `pip`:
|
|
89
|
+
|
|
90
|
+
```powershell
|
|
91
|
+
pip install webp-tui
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
After installation, `webp-converter` can be launched from any folder in PowerShell, Command Prompt, or Windows Terminal.
|
|
95
|
+
|
|
96
|
+
### Installing from local source (development)
|
|
97
|
+
|
|
98
|
+
```powershell
|
|
99
|
+
# Global editable install with uv:
|
|
100
|
+
uv tool install -e .
|
|
101
|
+
|
|
102
|
+
# Or inside a virtual environment:
|
|
103
|
+
pip install -e ".[dev]"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Running without installing globally
|
|
107
|
+
|
|
108
|
+
```powershell
|
|
109
|
+
pip install -r requirements.txt
|
|
110
|
+
python WebP-Image-Converter.py
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Or double-click / run `run-webp-converter.bat`.
|
|
114
|
+
|
|
115
|
+
## Usage
|
|
116
|
+
|
|
117
|
+
### Interactive Terminal UI (TUI — Default)
|
|
118
|
+
|
|
119
|
+
Run with no arguments, or pass a starting folder path:
|
|
120
|
+
|
|
121
|
+
```powershell
|
|
122
|
+
webp-converter
|
|
123
|
+
# or open directly on a folder:
|
|
124
|
+
webp-converter C:\Users\Name\Pictures\Batch
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Keybindings inside the TUI:
|
|
128
|
+
- `Ctrl+R`: Start conversion
|
|
129
|
+
- `Ctrl+D`: Dry run (preview output filenames without modifying files)
|
|
130
|
+
- `Esc`: Cancel a running batch
|
|
131
|
+
- `Ctrl+Q`: Quit
|
|
132
|
+
|
|
133
|
+
### Command-Line Interface (CLI — Secondary)
|
|
134
|
+
|
|
135
|
+
Pass `--cli` along with a folder path and flags for headless/scripted runs:
|
|
136
|
+
|
|
137
|
+
```powershell
|
|
138
|
+
webp-converter --cli C:\Users\Name\Pictures\Batch [OPTIONS]
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### Options
|
|
142
|
+
|
|
143
|
+
- `--cli`: Run in headless command-line mode instead of opening the TUI
|
|
144
|
+
- `--tui`: Force the interactive terminal UI (default)
|
|
145
|
+
- `--quality, -q`: WebP quality `0–100` (default: `90`)
|
|
146
|
+
- `--lossless` / `--lossy`: Pixel-exact lossless encoding / force lossy
|
|
147
|
+
- `--method, -m`: WebP compression effort `0–6` (`0` fastest, `6` smallest; default: `4`)
|
|
148
|
+
- `--keep-originals`: Keep original files after conversion (default)
|
|
149
|
+
- `--delete-originals`: Delete original files after successful conversion
|
|
150
|
+
- `--overwrite`: Overwrite existing `.webp` files instead of choosing a new name
|
|
151
|
+
- `--recursive` / `--no-recursive`: Scan subfolders recursively (default) or top-level only
|
|
152
|
+
- `--workers, -w`: Number of worker threads (default: CPU count)
|
|
153
|
+
- `--dry-run`: Preview planned conversions without modifying any files
|
|
154
|
+
- `--formats`: Supported extensions (default: `.jpg .jpeg .png .tif .tiff .bmp .gif`)
|
|
155
|
+
- `--log-file`: Write detailed logs to a file
|
|
156
|
+
- `--verbose, -v`: Enable debug logging
|
|
157
|
+
- `--config`: Path to a JSON configuration file
|
|
158
|
+
|
|
159
|
+
#### Examples
|
|
160
|
+
|
|
161
|
+
```powershell
|
|
162
|
+
# Convert a folder at quality 85
|
|
163
|
+
webp-converter --cli D:\Photos --quality 85
|
|
164
|
+
|
|
165
|
+
# Lossless conversion, deleting originals only after success
|
|
166
|
+
webp-converter --cli D:\Screenshots --lossless --delete-originals
|
|
167
|
+
|
|
168
|
+
# Top-level folder only, dry run
|
|
169
|
+
webp-converter --cli D:\Uploads --no-recursive --dry-run
|
|
170
|
+
|
|
171
|
+
# Maximum compression effort with 8 worker threads
|
|
172
|
+
webp-converter --cli D:\Exports -q 80 -m 6 -w 8
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Configuration
|
|
176
|
+
|
|
177
|
+
Settings can be saved from the TUI (`Save Config`) or edited in `config.json` (or `%APPDATA%\webp-converter\config.json` when installed globally):
|
|
178
|
+
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"webp_quality": 90,
|
|
182
|
+
"lossless": false,
|
|
183
|
+
"method": 4,
|
|
184
|
+
"delete_originals": false,
|
|
185
|
+
"overwrite": false,
|
|
186
|
+
"recursive": true,
|
|
187
|
+
"supported_formats": [".jpg", ".jpeg", ".png", ".tif", ".tiff", ".bmp", ".gif"],
|
|
188
|
+
"max_workers": 8
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Command-line flags always override `config.json`.
|
|
193
|
+
|
|
194
|
+
## Running the tests
|
|
195
|
+
|
|
196
|
+
```powershell
|
|
197
|
+
pip install -r requirements-dev.txt
|
|
198
|
+
python -m pytest
|
|
199
|
+
```
|
webp_tui-2.0.1/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# WebP Image Converter
|
|
2
|
+
|
|
3
|
+
A fast, safe batch image-to-WebP converter for Windows with an interactive **Terminal UI (TUI)** and a scriptable **CLI**, powered purely by Pillow (`libwebp`) — no external binaries required.
|
|
4
|
+
|
|
5
|
+
> Looking for v1.0 (Flask Web UI, `cwebp`/`ExifTool`, and Stable Diffusion metadata)? Check out the `v1.0.0` git tag.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Interactive Terminal UI (`webp-converter`)**: Browse folders, preview file counts and sizes, adjust settings, watch live per-file progress and space saved, or cancel mid-batch.
|
|
10
|
+
- **Scriptable CLI**: Pass a folder path and flags for automated/batch workflows with clean exit codes (`0` success, `1` partial failure/skip, `2` fatal error).
|
|
11
|
+
- **Pure Python / Pillow**: Converts JPG, JPEG, PNG, TIFF/TIF, BMP, and GIF (including **animated GIFs** to animated WebP) in-process — no `cwebp.exe` or `ExifTool` setup needed.
|
|
12
|
+
- **Lossy or pixel-exact lossless**: Configurable quality (`0–100`) and compression effort (`method 0–6`), or lossless encoding with exact RGB preservation under transparency.
|
|
13
|
+
- **Metadata preservation**: Carries over EXIF tags, ICC color profiles, XMP packets, and standard PNG/GIF/BMP text comments (`Author`, `Software`, `Comment`, `Creation Time`), and automatically applies EXIF orientation to static images.
|
|
14
|
+
- **Safe by default**:
|
|
15
|
+
- Original files are kept unless `--delete-originals` (or the TUI toggle) is enabled.
|
|
16
|
+
- Files are written atomically via temp files and originals are only removed after verified output.
|
|
17
|
+
- Never overwrites silently: `photo.jpg` + `photo.png` become `photo_jpg.webp` + `photo_png.webp`, and existing `.webp` files are left alone unless `--overwrite` is set.
|
|
18
|
+
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
- Windows 10 / 11 (Windows Terminal recommended for the TUI)
|
|
22
|
+
- Python 3.9 or higher
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
### Recommended: install globally from PyPI
|
|
27
|
+
|
|
28
|
+
Using `uv` or `pipx` (adds `webp-converter` to your `PATH` in an isolated environment):
|
|
29
|
+
|
|
30
|
+
```powershell
|
|
31
|
+
uv tool install webp-tui
|
|
32
|
+
# or
|
|
33
|
+
pipx install webp-tui
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or with `pip`:
|
|
37
|
+
|
|
38
|
+
```powershell
|
|
39
|
+
pip install webp-tui
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
After installation, `webp-converter` can be launched from any folder in PowerShell, Command Prompt, or Windows Terminal.
|
|
43
|
+
|
|
44
|
+
### Installing from local source (development)
|
|
45
|
+
|
|
46
|
+
```powershell
|
|
47
|
+
# Global editable install with uv:
|
|
48
|
+
uv tool install -e .
|
|
49
|
+
|
|
50
|
+
# Or inside a virtual environment:
|
|
51
|
+
pip install -e ".[dev]"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Running without installing globally
|
|
55
|
+
|
|
56
|
+
```powershell
|
|
57
|
+
pip install -r requirements.txt
|
|
58
|
+
python WebP-Image-Converter.py
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Or double-click / run `run-webp-converter.bat`.
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
### Interactive Terminal UI (TUI — Default)
|
|
66
|
+
|
|
67
|
+
Run with no arguments, or pass a starting folder path:
|
|
68
|
+
|
|
69
|
+
```powershell
|
|
70
|
+
webp-converter
|
|
71
|
+
# or open directly on a folder:
|
|
72
|
+
webp-converter C:\Users\Name\Pictures\Batch
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Keybindings inside the TUI:
|
|
76
|
+
- `Ctrl+R`: Start conversion
|
|
77
|
+
- `Ctrl+D`: Dry run (preview output filenames without modifying files)
|
|
78
|
+
- `Esc`: Cancel a running batch
|
|
79
|
+
- `Ctrl+Q`: Quit
|
|
80
|
+
|
|
81
|
+
### Command-Line Interface (CLI — Secondary)
|
|
82
|
+
|
|
83
|
+
Pass `--cli` along with a folder path and flags for headless/scripted runs:
|
|
84
|
+
|
|
85
|
+
```powershell
|
|
86
|
+
webp-converter --cli C:\Users\Name\Pictures\Batch [OPTIONS]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### Options
|
|
90
|
+
|
|
91
|
+
- `--cli`: Run in headless command-line mode instead of opening the TUI
|
|
92
|
+
- `--tui`: Force the interactive terminal UI (default)
|
|
93
|
+
- `--quality, -q`: WebP quality `0–100` (default: `90`)
|
|
94
|
+
- `--lossless` / `--lossy`: Pixel-exact lossless encoding / force lossy
|
|
95
|
+
- `--method, -m`: WebP compression effort `0–6` (`0` fastest, `6` smallest; default: `4`)
|
|
96
|
+
- `--keep-originals`: Keep original files after conversion (default)
|
|
97
|
+
- `--delete-originals`: Delete original files after successful conversion
|
|
98
|
+
- `--overwrite`: Overwrite existing `.webp` files instead of choosing a new name
|
|
99
|
+
- `--recursive` / `--no-recursive`: Scan subfolders recursively (default) or top-level only
|
|
100
|
+
- `--workers, -w`: Number of worker threads (default: CPU count)
|
|
101
|
+
- `--dry-run`: Preview planned conversions without modifying any files
|
|
102
|
+
- `--formats`: Supported extensions (default: `.jpg .jpeg .png .tif .tiff .bmp .gif`)
|
|
103
|
+
- `--log-file`: Write detailed logs to a file
|
|
104
|
+
- `--verbose, -v`: Enable debug logging
|
|
105
|
+
- `--config`: Path to a JSON configuration file
|
|
106
|
+
|
|
107
|
+
#### Examples
|
|
108
|
+
|
|
109
|
+
```powershell
|
|
110
|
+
# Convert a folder at quality 85
|
|
111
|
+
webp-converter --cli D:\Photos --quality 85
|
|
112
|
+
|
|
113
|
+
# Lossless conversion, deleting originals only after success
|
|
114
|
+
webp-converter --cli D:\Screenshots --lossless --delete-originals
|
|
115
|
+
|
|
116
|
+
# Top-level folder only, dry run
|
|
117
|
+
webp-converter --cli D:\Uploads --no-recursive --dry-run
|
|
118
|
+
|
|
119
|
+
# Maximum compression effort with 8 worker threads
|
|
120
|
+
webp-converter --cli D:\Exports -q 80 -m 6 -w 8
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Configuration
|
|
124
|
+
|
|
125
|
+
Settings can be saved from the TUI (`Save Config`) or edited in `config.json` (or `%APPDATA%\webp-converter\config.json` when installed globally):
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"webp_quality": 90,
|
|
130
|
+
"lossless": false,
|
|
131
|
+
"method": 4,
|
|
132
|
+
"delete_originals": false,
|
|
133
|
+
"overwrite": false,
|
|
134
|
+
"recursive": true,
|
|
135
|
+
"supported_formats": [".jpg", ".jpeg", ".png", ".tif", ".tiff", ".bmp", ".gif"],
|
|
136
|
+
"max_workers": 8
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Command-line flags always override `config.json`.
|
|
141
|
+
|
|
142
|
+
## Running the tests
|
|
143
|
+
|
|
144
|
+
```powershell
|
|
145
|
+
pip install -r requirements-dev.txt
|
|
146
|
+
python -m pytest
|
|
147
|
+
```
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "webp-tui"
|
|
7
|
+
version = "2.0.1"
|
|
8
|
+
description = "Batch image-to-WebP converter with an interactive terminal UI (TUI) and CLI for Windows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "RenX86" },
|
|
13
|
+
]
|
|
14
|
+
requires-python = ">=3.9"
|
|
15
|
+
keywords = ["webp", "image", "converter", "tui", "textual", "pillow", "cli"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 5 - Production/Stable",
|
|
18
|
+
"Environment :: Console",
|
|
19
|
+
"Intended Audience :: End Users/Desktop",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Operating System :: Microsoft :: Windows",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3.9",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
|
|
29
|
+
]
|
|
30
|
+
dependencies = [
|
|
31
|
+
"Pillow>=9.0.0",
|
|
32
|
+
"textual>=0.80.0",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
dev = [
|
|
37
|
+
"pytest>=7.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/RenX86/WebP-Image-Converter"
|
|
42
|
+
Repository = "https://github.com/RenX86/WebP-Image-Converter"
|
|
43
|
+
Issues = "https://github.com/RenX86/WebP-Image-Converter/issues"
|
|
44
|
+
|
|
45
|
+
[project.scripts]
|
|
46
|
+
webp-converter = "webp_converter.main:main"
|
|
47
|
+
|
|
48
|
+
[tool.setuptools.packages.find]
|
|
49
|
+
include = ["webp_converter*"]
|
webp_tui-2.0.1/setup.cfg
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import os
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
import threading
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
from PIL import Image, ImageCms, PngImagePlugin
|
|
9
|
+
|
|
10
|
+
from webp_converter.cli import build_parser, build_settings
|
|
11
|
+
from webp_converter.config import Settings
|
|
12
|
+
from webp_converter.core import (
|
|
13
|
+
BatchEvent,
|
|
14
|
+
convert_file,
|
|
15
|
+
plan_conversions,
|
|
16
|
+
run_batch,
|
|
17
|
+
scan_folder,
|
|
18
|
+
to_exif_datetime,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# ---------------------------------------------------------------- planning
|
|
23
|
+
|
|
24
|
+
def test_plan_simple(tmp_path):
|
|
25
|
+
a = str(tmp_path / "a.png")
|
|
26
|
+
open(a, "wb").close()
|
|
27
|
+
plan, skipped = plan_conversions([a])
|
|
28
|
+
assert plan == [(a, str(tmp_path / "a.webp"))] and skipped == []
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_plan_same_stem_gets_distinct_names(tmp_path):
|
|
32
|
+
jpg, png = str(tmp_path / "photo.jpg"), str(tmp_path / "photo.png")
|
|
33
|
+
plan, skipped = plan_conversions([jpg, png])
|
|
34
|
+
outputs = dict(plan)
|
|
35
|
+
assert outputs[jpg].endswith("photo_jpg.webp")
|
|
36
|
+
assert outputs[png].endswith("photo_png.webp")
|
|
37
|
+
assert skipped == []
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@pytest.mark.skipif(not sys.platform.startswith("win"), reason="case-insensitive filesystem")
|
|
41
|
+
def test_plan_case_insensitive_collision(tmp_path):
|
|
42
|
+
a, b = str(tmp_path / "Photo.jpg"), str(tmp_path / "photo.PNG")
|
|
43
|
+
plan, _ = plan_conversions([a, b])
|
|
44
|
+
assert len({os.path.normcase(d) for _, d in plan}) == 2
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_plan_never_overwrites_existing_webp(tmp_path):
|
|
48
|
+
(tmp_path / "a.webp").write_bytes(b"existing")
|
|
49
|
+
a = str(tmp_path / "a.png")
|
|
50
|
+
plan, _ = plan_conversions([a])
|
|
51
|
+
assert plan == [(a, str(tmp_path / "a_png.webp"))]
|
|
52
|
+
plan, _ = plan_conversions([a], overwrite=True)
|
|
53
|
+
assert plan == [(a, str(tmp_path / "a.webp"))]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_plan_skips_when_all_names_taken(tmp_path):
|
|
57
|
+
(tmp_path / "a.webp").write_bytes(b"x")
|
|
58
|
+
(tmp_path / "a_png.webp").write_bytes(b"x")
|
|
59
|
+
a = str(tmp_path / "a.png")
|
|
60
|
+
plan, skipped = plan_conversions([a])
|
|
61
|
+
assert plan == [] and skipped == [a]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# ---------------------------------------------------------------- scanning & config
|
|
65
|
+
|
|
66
|
+
def test_scan_non_recursive(tmp_path):
|
|
67
|
+
sub = tmp_path / "sub"
|
|
68
|
+
sub.mkdir()
|
|
69
|
+
Image.new("RGB", (8, 8)).save(tmp_path / "top.png")
|
|
70
|
+
Image.new("RGB", (8, 8)).save(sub / "nested.png")
|
|
71
|
+
assert len(scan_folder(str(tmp_path), {".png"}, recursive=True)) == 2
|
|
72
|
+
assert len(scan_folder(str(tmp_path), {".png"}, recursive=False)) == 1
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_cli_overrides_config():
|
|
76
|
+
parser = build_parser()
|
|
77
|
+
cfg = {"webp_quality": "80", "delete_originals": True, "max_workers": 3, "lossless": True, "method": 6}
|
|
78
|
+
s = build_settings(parser.parse_args(["x"]), cfg)
|
|
79
|
+
assert (s.quality, s.delete_originals, s.max_workers, s.lossless, s.method) == (80, True, 3, True, 6)
|
|
80
|
+
s = build_settings(parser.parse_args(["x", "--keep-originals", "--lossy", "-q", "50", "-m", "2"]), cfg)
|
|
81
|
+
assert (s.quality, s.delete_originals, s.lossless, s.method) == (50, False, False, 2)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_default_keeps_originals():
|
|
85
|
+
s = build_settings(build_parser().parse_args(["x"]), {})
|
|
86
|
+
assert s.delete_originals is False
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@pytest.mark.parametrize("value,expected", [
|
|
90
|
+
("2023-05-01T10:20:30", "2023:05:01 10:20:30"),
|
|
91
|
+
("Mon, 01 May 2023 10:20:30 +0000", "2023:05:01 10:20:30"),
|
|
92
|
+
("2023:05:01 10:20:30", "2023:05:01 10:20:30"),
|
|
93
|
+
("not a date", None),
|
|
94
|
+
])
|
|
95
|
+
def test_to_exif_datetime(value, expected):
|
|
96
|
+
assert to_exif_datetime(value) == expected
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
# ---------------------------------------------------------------- conversion & metadata
|
|
100
|
+
|
|
101
|
+
def test_jpeg_exif_and_icc_preserved_and_unicode_path(tmp_path):
|
|
102
|
+
src = str(tmp_path / "ünïcode photo.jpg")
|
|
103
|
+
im = Image.new("RGB", (16, 16), "blue")
|
|
104
|
+
exif = im.getexif()
|
|
105
|
+
exif[0x013B] = "Tester"
|
|
106
|
+
exif[0x010E] = "Sample description"
|
|
107
|
+
srgb = ImageCms.ImageCmsProfile(ImageCms.createProfile("sRGB")).tobytes()
|
|
108
|
+
im.save(src, exif=exif, icc_profile=srgb)
|
|
109
|
+
|
|
110
|
+
dst = str(tmp_path / "ünïcode photo.webp")
|
|
111
|
+
ok, before, after, err = convert_file(Settings(delete_originals=True), src, dst)
|
|
112
|
+
assert ok and err == "" and before > 0 and after > 0
|
|
113
|
+
assert not os.path.exists(src)
|
|
114
|
+
with Image.open(dst) as out:
|
|
115
|
+
assert out.getexif().get(0x013B) == "Tester"
|
|
116
|
+
assert out.getexif().get(0x010E) == "Sample description"
|
|
117
|
+
assert out.info.get("icc_profile") == srgb
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_exif_orientation_applied_on_convert(tmp_path):
|
|
121
|
+
src = str(tmp_path / "rotated.jpg")
|
|
122
|
+
im = Image.new("RGB", (20, 10), "red")
|
|
123
|
+
exif = im.getexif()
|
|
124
|
+
exif[0x0112] = 6 # Rotate 90 CW -> should become 10x20 upright
|
|
125
|
+
im.save(src, exif=exif)
|
|
126
|
+
|
|
127
|
+
dst = str(tmp_path / "rotated.webp")
|
|
128
|
+
ok, _, _, _ = convert_file(Settings(), src, dst)
|
|
129
|
+
assert ok
|
|
130
|
+
with Image.open(dst) as out:
|
|
131
|
+
assert out.size == (10, 20)
|
|
132
|
+
assert out.getexif().get(0x0112) in (None, 1)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def test_png_xmp_and_generic_text_preserved(tmp_path):
|
|
136
|
+
src = str(tmp_path / "meta.png")
|
|
137
|
+
info = PngImagePlugin.PngInfo()
|
|
138
|
+
info.add_text("Author", "Alice")
|
|
139
|
+
info.add_text("Comment", "Multi-line\ncomment ✓")
|
|
140
|
+
info.add_text("XML:com.adobe.xmp", "<x:xmpmeta>hello</x:xmpmeta>")
|
|
141
|
+
Image.new("RGB", (16, 16), "green").save(src, pnginfo=info)
|
|
142
|
+
|
|
143
|
+
dst = str(tmp_path / "meta.webp")
|
|
144
|
+
ok, _, _, _ = convert_file(Settings(), src, dst)
|
|
145
|
+
assert ok
|
|
146
|
+
with Image.open(dst) as out:
|
|
147
|
+
assert out.getexif().get(0x013B) == "Alice"
|
|
148
|
+
assert b"hello" in (out.info.get("xmp") or b"")
|
|
149
|
+
uc = out.getexif().get_ifd(0x8769).get(0x9286, b"")
|
|
150
|
+
assert b"Multi-line" in uc or "Multi-line".encode("utf-16-be") in uc
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def test_failed_encode_keeps_original_and_no_partial_output(tmp_path):
|
|
154
|
+
src = str(tmp_path / "broken.png")
|
|
155
|
+
with open(src, "wb") as f:
|
|
156
|
+
f.write(b"not really a png")
|
|
157
|
+
dst = str(tmp_path / "broken.webp")
|
|
158
|
+
ok, _, _, err = convert_file(Settings(delete_originals=True), src, dst)
|
|
159
|
+
assert not ok and err
|
|
160
|
+
assert os.path.exists(src)
|
|
161
|
+
assert not os.path.exists(dst)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def test_lossless_is_pixel_exact(tmp_path):
|
|
165
|
+
src = str(tmp_path / "px.png")
|
|
166
|
+
img = Image.new("RGBA", (8, 8))
|
|
167
|
+
img.putdata([(i * 4, 255 - i * 4, (i * 37) % 256, 0 if i % 2 == 0 else 180) for i in range(64)])
|
|
168
|
+
img.save(src)
|
|
169
|
+
dst = str(tmp_path / "px.webp")
|
|
170
|
+
ok, _, _, _ = convert_file(Settings(lossless=True), src, dst)
|
|
171
|
+
assert ok
|
|
172
|
+
with Image.open(dst) as out:
|
|
173
|
+
assert out.convert("RGBA").tobytes() == img.tobytes()
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
@pytest.mark.parametrize("ext", [".bmp", ".gif", ".tif"])
|
|
177
|
+
def test_static_formats_convert(tmp_path, ext):
|
|
178
|
+
src = str(tmp_path / f"img{ext}")
|
|
179
|
+
Image.new("RGB", (16, 16), "green").save(src)
|
|
180
|
+
dst = str(tmp_path / "img.webp")
|
|
181
|
+
ok, _, _, _ = convert_file(Settings(), src, dst)
|
|
182
|
+
assert ok
|
|
183
|
+
with Image.open(dst) as out:
|
|
184
|
+
assert out.size == (16, 16)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def test_animated_gif_preserves_animation(tmp_path):
|
|
188
|
+
src = str(tmp_path / "anim.gif")
|
|
189
|
+
frames = [Image.new("RGB", (16, 16), c) for c in ("red", "green", "blue")]
|
|
190
|
+
frames[0].save(src, save_all=True, append_images=frames[1:], duration=100, loop=0)
|
|
191
|
+
dst = str(tmp_path / "anim.webp")
|
|
192
|
+
ok, _, _, _ = convert_file(Settings(delete_originals=True), src, dst)
|
|
193
|
+
assert ok
|
|
194
|
+
with Image.open(dst) as out:
|
|
195
|
+
assert getattr(out, "n_frames", 1) == 3
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def test_run_batch_events_and_cancel(tmp_path):
|
|
199
|
+
plan = []
|
|
200
|
+
for i in range(6):
|
|
201
|
+
src = str(tmp_path / f"img_{i}.png")
|
|
202
|
+
Image.new("RGB", (8, 8), "red").save(src)
|
|
203
|
+
plan.append((src, str(tmp_path / f"img_{i}.webp")))
|
|
204
|
+
|
|
205
|
+
events: list[BatchEvent] = []
|
|
206
|
+
cancel = threading.Event()
|
|
207
|
+
|
|
208
|
+
def on_event(ev: BatchEvent):
|
|
209
|
+
events.append(ev)
|
|
210
|
+
if ev.kind == "file_completed":
|
|
211
|
+
cancel.set()
|
|
212
|
+
|
|
213
|
+
summary = run_batch(Settings(max_workers=1), plan, on_event=on_event, cancel_event=cancel)
|
|
214
|
+
assert summary.cancelled is True
|
|
215
|
+
assert summary.succeeded < len(plan)
|
|
216
|
+
assert events[0].kind == "batch_started" and events[-1].kind == "batch_finished"
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def test_cli_exit_codes_and_collision_end_to_end(tmp_path):
|
|
220
|
+
repo = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
221
|
+
script = os.path.join(repo, "WebP-Image-Converter.py")
|
|
222
|
+
Image.new("RGB", (8, 8), "red").save(tmp_path / "same.png")
|
|
223
|
+
Image.new("RGB", (8, 8), "blue").save(tmp_path / "same.jpg")
|
|
224
|
+
|
|
225
|
+
r = subprocess.run(
|
|
226
|
+
[sys.executable, script, "--cli", str(tmp_path), "--delete-originals", "-w", "2"],
|
|
227
|
+
capture_output=True, text=True, encoding="utf-8",
|
|
228
|
+
)
|
|
229
|
+
assert r.returncode == 0, r.stderr
|
|
230
|
+
assert sorted(os.listdir(tmp_path)) == ["same_jpg.webp", "same_png.webp"]
|
|
231
|
+
|
|
232
|
+
r = subprocess.run([sys.executable, script, "--cli", str(tmp_path / "missing")], capture_output=True)
|
|
233
|
+
assert r.returncode == 2
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def test_main_dispatches_to_tui_by_default(monkeypatch):
|
|
237
|
+
from webp_converter import main as main_mod
|
|
238
|
+
called = {}
|
|
239
|
+
monkeypatch.setattr("webp_converter.tui.run_tui", lambda initial_folder=None: called.setdefault("tui", initial_folder))
|
|
240
|
+
monkeypatch.setattr("webp_converter.cli.run_cli", lambda argv=None: (called.setdefault("cli", argv), 0)[1])
|
|
241
|
+
|
|
242
|
+
assert main_mod.main([]) == 0
|
|
243
|
+
assert called["tui"] is None
|
|
244
|
+
called.clear()
|
|
245
|
+
|
|
246
|
+
assert main_mod.main([r"D:\Photos"]) == 0
|
|
247
|
+
assert called["tui"] == r"D:\Photos"
|
|
248
|
+
called.clear()
|
|
249
|
+
|
|
250
|
+
assert main_mod.main(["--cli", r"D:\Photos", "-q", "80"]) == 0
|
|
251
|
+
assert called["cli"] == [r"D:\Photos", "-q", "80"]
|