imgbytesizer 0.2.2__tar.gz → 0.2.4__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.
- {imgbytesizer-0.2.2/imgbytesizer.egg-info → imgbytesizer-0.2.4}/PKG-INFO +40 -14
- imgbytesizer-0.2.2/PKG-INFO → imgbytesizer-0.2.4/README.md +24 -20
- imgbytesizer-0.2.4/pyproject.toml +40 -0
- {imgbytesizer-0.2.2 → imgbytesizer-0.2.4/src}/imgbytesizer/__init__.py +1 -1
- imgbytesizer-0.2.4/src/imgbytesizer/formatter.py +17 -0
- imgbytesizer-0.2.4/src/imgbytesizer/logger.py +128 -0
- {imgbytesizer-0.2.2 → imgbytesizer-0.2.4/src}/imgbytesizer/main.py +31 -14
- imgbytesizer-0.2.4/src/imgbytesizer/py.typed +1 -0
- {imgbytesizer-0.2.2 → imgbytesizer-0.2.4/src}/imgbytesizer/resizer.py +91 -67
- {imgbytesizer-0.2.2 → imgbytesizer-0.2.4/src}/imgbytesizer/utils.py +8 -10
- imgbytesizer-0.2.2/README.md +0 -164
- imgbytesizer-0.2.2/imgbytesizer/formatter.py +0 -18
- imgbytesizer-0.2.2/imgbytesizer/logger.py +0 -206
- imgbytesizer-0.2.2/imgbytesizer.egg-info/SOURCES.txt +0 -20
- imgbytesizer-0.2.2/imgbytesizer.egg-info/dependency_links.txt +0 -1
- imgbytesizer-0.2.2/imgbytesizer.egg-info/entry_points.txt +0 -2
- imgbytesizer-0.2.2/imgbytesizer.egg-info/requires.txt +0 -2
- imgbytesizer-0.2.2/imgbytesizer.egg-info/top_level.txt +0 -1
- imgbytesizer-0.2.2/pyproject.toml +0 -16
- imgbytesizer-0.2.2/setup.cfg +0 -4
- imgbytesizer-0.2.2/tests/test_formatter.py +0 -16
- imgbytesizer-0.2.2/tests/test_logger.py +0 -48
- imgbytesizer-0.2.2/tests/test_main.py +0 -128
- imgbytesizer-0.2.2/tests/test_resizer.py +0 -291
- imgbytesizer-0.2.2/tests/test_utils.py +0 -99
- {imgbytesizer-0.2.2 → imgbytesizer-0.2.4}/LICENSE +0 -0
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: imgbytesizer
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: A CLI tool to resize images to a target file size.
|
|
5
|
-
|
|
6
|
-
License: MIT License
|
|
5
|
+
License: MIT
|
|
7
6
|
Keywords: image,resize,compression,cli,optimize
|
|
7
|
+
Author: pyyupsk
|
|
8
|
+
Author-email: contact@fasu.dev
|
|
8
9
|
Requires-Python: >=3.9
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Requires-Dist: pillow (>=11.2.1,<12.0.0)
|
|
18
|
+
Requires-Dist: pyfiglet (>=1.0.2,<2.0.0)
|
|
19
|
+
Requires-Dist: tabulate (>=0.9.0,<0.10.0)
|
|
9
20
|
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
Requires-Dist: Pillow>=11.0.0
|
|
12
|
-
Requires-Dist: tabulate>=0.9.0
|
|
13
|
-
Dynamic: license-file
|
|
14
21
|
|
|
15
22
|
# ImgByteSizer
|
|
16
23
|
|
|
@@ -61,7 +68,7 @@ imgbytesizer large_image.jpg 300KB --min-dimension 400
|
|
|
61
68
|
### Command-Line Options
|
|
62
69
|
|
|
63
70
|
```bash
|
|
64
|
-
usage: imgbytesizer [-h] [-o OUTPUT] [-f {jpg,jpeg,png,webp}] [--min-dimension MIN_DIMENSION] [--no-exact] [
|
|
71
|
+
usage: imgbytesizer [-h] [-o OUTPUT] [-f {jpg,jpeg,png,webp}] [--min-dimension MIN_DIMENSION] [--no-exact] [--debug] [-q] [-v] [image_path] [target_size]
|
|
65
72
|
|
|
66
73
|
Resize an image to match a target file size
|
|
67
74
|
|
|
@@ -71,15 +78,28 @@ positional arguments:
|
|
|
71
78
|
|
|
72
79
|
options:
|
|
73
80
|
-h, --help show this help message and exit
|
|
81
|
+
-v, --version Show version information
|
|
82
|
+
|
|
83
|
+
primary options:
|
|
74
84
|
-o, --output OUTPUT Output path (default: input_resized.ext)
|
|
75
85
|
-f, --format {jpg,jpeg,png,webp}
|
|
76
86
|
Output format
|
|
87
|
+
|
|
88
|
+
advanced options:
|
|
77
89
|
--min-dimension MIN_DIMENSION
|
|
78
90
|
Minimum width/height in pixels
|
|
79
91
|
--no-exact Do not pad file to get exact target size
|
|
80
|
-
|
|
92
|
+
|
|
93
|
+
utility:
|
|
81
94
|
--debug Enable debug logging
|
|
82
95
|
-q, --quiet Minimal output
|
|
96
|
+
|
|
97
|
+
examples:
|
|
98
|
+
imgbytesizer image.jpg 500KB # Resize to 500 KB
|
|
99
|
+
imgbytesizer photo.png 2MB -o small_photo.png # Resize to 2 MB with custom output
|
|
100
|
+
imgbytesizer image.jpg 100KB -f webp # Resize and convert to WebP
|
|
101
|
+
imgbytesizer large.jpg 50KB --min-dimension 200 # Ensure min dimension is 200px
|
|
102
|
+
imgbytesizer -v # Show version information
|
|
83
103
|
```
|
|
84
104
|
|
|
85
105
|
## How It Works
|
|
@@ -164,10 +184,15 @@ imgbytesizer profile_pic.jpg 400KB --min-dimension 400
|
|
|
164
184
|
|
|
165
185
|
## Requirements
|
|
166
186
|
|
|
167
|
-
|
|
168
|
-
-
|
|
169
|
-
|
|
170
|
-
|
|
187
|
+
```toml
|
|
188
|
+
requires-python = ">=3.9"
|
|
189
|
+
|
|
190
|
+
dependencies = [
|
|
191
|
+
"pillow (>=11.2.1,<12.0.0)",
|
|
192
|
+
"pyfiglet (>=1.0.2,<2.0.0)",
|
|
193
|
+
"tabulate (>=0.9.0,<0.10.0)",
|
|
194
|
+
]
|
|
195
|
+
```
|
|
171
196
|
|
|
172
197
|
## Contributing
|
|
173
198
|
|
|
@@ -176,3 +201,4 @@ Contributions are welcome! Feel free to submit issues or pull requests.
|
|
|
176
201
|
## License
|
|
177
202
|
|
|
178
203
|
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
204
|
+
|
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: imgbytesizer
|
|
3
|
-
Version: 0.2.2
|
|
4
|
-
Summary: A CLI tool to resize images to a target file size.
|
|
5
|
-
Author-email: pyyupsk <contact@fasu.dev>
|
|
6
|
-
License: MIT License
|
|
7
|
-
Keywords: image,resize,compression,cli,optimize
|
|
8
|
-
Requires-Python: >=3.9
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
Requires-Dist: Pillow>=11.0.0
|
|
12
|
-
Requires-Dist: tabulate>=0.9.0
|
|
13
|
-
Dynamic: license-file
|
|
14
|
-
|
|
15
1
|
# ImgByteSizer
|
|
16
2
|
|
|
17
3
|
[](https://pypi.org/project/imgbytesizer/)
|
|
@@ -61,7 +47,7 @@ imgbytesizer large_image.jpg 300KB --min-dimension 400
|
|
|
61
47
|
### Command-Line Options
|
|
62
48
|
|
|
63
49
|
```bash
|
|
64
|
-
usage: imgbytesizer [-h] [-o OUTPUT] [-f {jpg,jpeg,png,webp}] [--min-dimension MIN_DIMENSION] [--no-exact] [
|
|
50
|
+
usage: imgbytesizer [-h] [-o OUTPUT] [-f {jpg,jpeg,png,webp}] [--min-dimension MIN_DIMENSION] [--no-exact] [--debug] [-q] [-v] [image_path] [target_size]
|
|
65
51
|
|
|
66
52
|
Resize an image to match a target file size
|
|
67
53
|
|
|
@@ -71,15 +57,28 @@ positional arguments:
|
|
|
71
57
|
|
|
72
58
|
options:
|
|
73
59
|
-h, --help show this help message and exit
|
|
60
|
+
-v, --version Show version information
|
|
61
|
+
|
|
62
|
+
primary options:
|
|
74
63
|
-o, --output OUTPUT Output path (default: input_resized.ext)
|
|
75
64
|
-f, --format {jpg,jpeg,png,webp}
|
|
76
65
|
Output format
|
|
66
|
+
|
|
67
|
+
advanced options:
|
|
77
68
|
--min-dimension MIN_DIMENSION
|
|
78
69
|
Minimum width/height in pixels
|
|
79
70
|
--no-exact Do not pad file to get exact target size
|
|
80
|
-
|
|
71
|
+
|
|
72
|
+
utility:
|
|
81
73
|
--debug Enable debug logging
|
|
82
74
|
-q, --quiet Minimal output
|
|
75
|
+
|
|
76
|
+
examples:
|
|
77
|
+
imgbytesizer image.jpg 500KB # Resize to 500 KB
|
|
78
|
+
imgbytesizer photo.png 2MB -o small_photo.png # Resize to 2 MB with custom output
|
|
79
|
+
imgbytesizer image.jpg 100KB -f webp # Resize and convert to WebP
|
|
80
|
+
imgbytesizer large.jpg 50KB --min-dimension 200 # Ensure min dimension is 200px
|
|
81
|
+
imgbytesizer -v # Show version information
|
|
83
82
|
```
|
|
84
83
|
|
|
85
84
|
## How It Works
|
|
@@ -164,10 +163,15 @@ imgbytesizer profile_pic.jpg 400KB --min-dimension 400
|
|
|
164
163
|
|
|
165
164
|
## Requirements
|
|
166
165
|
|
|
167
|
-
|
|
168
|
-
-
|
|
169
|
-
|
|
170
|
-
|
|
166
|
+
```toml
|
|
167
|
+
requires-python = ">=3.9"
|
|
168
|
+
|
|
169
|
+
dependencies = [
|
|
170
|
+
"pillow (>=11.2.1,<12.0.0)",
|
|
171
|
+
"pyfiglet (>=1.0.2,<2.0.0)",
|
|
172
|
+
"tabulate (>=0.9.0,<0.10.0)",
|
|
173
|
+
]
|
|
174
|
+
```
|
|
171
175
|
|
|
172
176
|
## Contributing
|
|
173
177
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "imgbytesizer"
|
|
3
|
+
version = "0.2.4"
|
|
4
|
+
description = "A CLI tool to resize images to a target file size."
|
|
5
|
+
keywords = ["image", "resize", "compression", "cli", "optimize"]
|
|
6
|
+
|
|
7
|
+
authors = [{ name = "pyyupsk", email = "contact@fasu.dev" }]
|
|
8
|
+
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT License" }
|
|
11
|
+
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
|
|
14
|
+
dependencies = [
|
|
15
|
+
"pillow (>=11.2.1,<12.0.0)",
|
|
16
|
+
"pyfiglet (>=1.0.2,<2.0.0)",
|
|
17
|
+
"tabulate (>=0.9.0,<0.10.0)",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.scripts]
|
|
21
|
+
imgbytesizer = "imgbytesizer.main:main"
|
|
22
|
+
|
|
23
|
+
[tool.poetry]
|
|
24
|
+
packages = [{ include = "imgbytesizer", from = "src" }]
|
|
25
|
+
|
|
26
|
+
[tool.poetry.group.dev.dependencies]
|
|
27
|
+
flake8 = "^7.2.0"
|
|
28
|
+
pytest = "^8.3.5"
|
|
29
|
+
pytest-cov = "^6.1.1"
|
|
30
|
+
requests = "^2.32.3"
|
|
31
|
+
types-requests = "^2.32.0.20250515"
|
|
32
|
+
tomli = "^2.2.1"
|
|
33
|
+
types-tabulate = "^0.9.0.20241207"
|
|
34
|
+
vulture = "^2.14"
|
|
35
|
+
yapf = "^0.43.0"
|
|
36
|
+
tox = "^4.26.0"
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
40
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Terminal formatting utilities for imgbytesizer.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Union
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def format_filesize(size_bytes: Union[int, float, None]) -> str:
|
|
9
|
+
"""Format file size in bytes to human-readable string."""
|
|
10
|
+
if size_bytes is None:
|
|
11
|
+
return "N/A"
|
|
12
|
+
size: float = float(size_bytes)
|
|
13
|
+
for unit in ["B", "KB", "MB", "GB"]:
|
|
14
|
+
if size < 1024:
|
|
15
|
+
return f"{size:.1f}{unit}"
|
|
16
|
+
size /= 1024
|
|
17
|
+
return f"{size:.1f}TB"
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Logging utilities for imgbytesizer.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from typing import Final, Optional, TextIO, Tuple
|
|
7
|
+
|
|
8
|
+
from .formatter import format_filesize
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# ANSI Color Codes for beautiful terminal output
|
|
12
|
+
class Colors:
|
|
13
|
+
RED: Final[str] = "\033[91m"
|
|
14
|
+
GREEN: Final[str] = "\033[92m"
|
|
15
|
+
YELLOW: Final[str] = "\033[93m"
|
|
16
|
+
ENDC: Final[str] = "\033[0m"
|
|
17
|
+
UNDERLINE: Final[str] = "\033[4m"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def setup_logger() -> logging.Logger:
|
|
21
|
+
"""Set up and configure the logger."""
|
|
22
|
+
logger: logging.Logger = logging.getLogger("imgbytesizer")
|
|
23
|
+
logger.setLevel(logging.INFO)
|
|
24
|
+
|
|
25
|
+
# Create console handler
|
|
26
|
+
handler: logging.StreamHandler[TextIO] = logging.StreamHandler() # type: ignore
|
|
27
|
+
handler.setLevel(logging.INFO)
|
|
28
|
+
|
|
29
|
+
# Create formatter
|
|
30
|
+
formatter: logging.Formatter = logging.Formatter(
|
|
31
|
+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
32
|
+
)
|
|
33
|
+
handler.setFormatter(formatter)
|
|
34
|
+
|
|
35
|
+
# Add handler to logger
|
|
36
|
+
logger.addHandler(handler)
|
|
37
|
+
|
|
38
|
+
return logger
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def print_result(label: str, value: str, status: Optional[str] = None) -> None:
|
|
42
|
+
"""Print a name-value pair with optional status color."""
|
|
43
|
+
if status == "good":
|
|
44
|
+
value = f"{Colors.GREEN}{value}{Colors.ENDC}"
|
|
45
|
+
elif status == "bad":
|
|
46
|
+
value = f"{Colors.RED}{value}{Colors.ENDC}"
|
|
47
|
+
elif status == "warning":
|
|
48
|
+
value = f"{Colors.YELLOW}{value}{Colors.ENDC}"
|
|
49
|
+
|
|
50
|
+
print(f"{label:12} {value}")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def print_comparison_table(
|
|
54
|
+
orig_size: int,
|
|
55
|
+
orig_dimensions: Tuple[int, int],
|
|
56
|
+
final_size: int,
|
|
57
|
+
final_dimensions: Tuple[int, int],
|
|
58
|
+
target_size: int,
|
|
59
|
+
) -> None:
|
|
60
|
+
"""Print a comparison table of original and final image properties."""
|
|
61
|
+
print("\nComparison:")
|
|
62
|
+
print("-" * 40)
|
|
63
|
+
|
|
64
|
+
# Original dimensions
|
|
65
|
+
orig_width, orig_height = orig_dimensions
|
|
66
|
+
print_result("Original", f"{orig_width} × {orig_height} pixels")
|
|
67
|
+
print_result("Size", format_filesize(orig_size))
|
|
68
|
+
|
|
69
|
+
# Final dimensions
|
|
70
|
+
final_width, final_height = final_dimensions
|
|
71
|
+
print_result("Final", f"{final_width} × {final_height} pixels")
|
|
72
|
+
print_result("Size", format_filesize(final_size))
|
|
73
|
+
|
|
74
|
+
# Target size
|
|
75
|
+
print_result("Target", format_filesize(target_size))
|
|
76
|
+
|
|
77
|
+
# Calculate and print differences
|
|
78
|
+
size_diff: int = final_size - orig_size
|
|
79
|
+
size_diff_percent: float = (size_diff / orig_size) * 100
|
|
80
|
+
size_status: str = "good" if size_diff <= 0 else "bad"
|
|
81
|
+
|
|
82
|
+
print_result(
|
|
83
|
+
"Size change",
|
|
84
|
+
f"{format_filesize(size_diff)} ({size_diff_percent:+.1f}%)",
|
|
85
|
+
size_status,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
# Dimension changes
|
|
89
|
+
width_diff: int = final_width - orig_width
|
|
90
|
+
height_diff: int = final_height - orig_height
|
|
91
|
+
width_diff_percent: float = (width_diff / orig_width) * 100
|
|
92
|
+
height_diff_percent: float = (height_diff / orig_height) * 100
|
|
93
|
+
|
|
94
|
+
print_result(
|
|
95
|
+
"Width change",
|
|
96
|
+
f"{width_diff:+d} pixels ({width_diff_percent:+.1f}%)",
|
|
97
|
+
"good" if width_diff <= 0 else "warning",
|
|
98
|
+
)
|
|
99
|
+
print_result(
|
|
100
|
+
"Height change",
|
|
101
|
+
f"{height_diff:+d} pixels ({height_diff_percent:+.1f}%)",
|
|
102
|
+
"good" if height_diff <= 0 else "warning",
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
print("-" * 40)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def print_processing_step(step: int, message: str) -> None:
|
|
109
|
+
"""Print a processing step with step number."""
|
|
110
|
+
print(f"\n[{step}] {message}")
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def print_progress_bar(
|
|
114
|
+
iteration: int,
|
|
115
|
+
total: int,
|
|
116
|
+
prefix: str = "",
|
|
117
|
+
suffix: str = "",
|
|
118
|
+
decimals: int = 1,
|
|
119
|
+
length: int = 50,
|
|
120
|
+
fill: str = "█",
|
|
121
|
+
) -> None:
|
|
122
|
+
"""Print a progress bar."""
|
|
123
|
+
percent: str = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
|
|
124
|
+
filled_length: int = int(length * iteration // total)
|
|
125
|
+
bar: str = fill * filled_length + "-" * (length - filled_length)
|
|
126
|
+
print(f"\r{prefix} |{bar}| {percent}% {suffix}", end="\r")
|
|
127
|
+
if iteration == total:
|
|
128
|
+
print()
|
|
@@ -7,21 +7,27 @@ import logging
|
|
|
7
7
|
import sys
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
|
|
10
|
+
from pyfiglet import Figlet
|
|
11
|
+
|
|
10
12
|
from .logger import setup_logger
|
|
11
13
|
from .resizer import resize_to_target_filesize
|
|
12
14
|
from .utils import IMG_FORMATS, parse_filesize
|
|
13
15
|
|
|
16
|
+
f: Figlet = Figlet(font="slant")
|
|
17
|
+
|
|
14
18
|
|
|
15
19
|
def main() -> int:
|
|
16
20
|
"""Main entry point for the CLI."""
|
|
17
21
|
# Setup logger
|
|
18
|
-
logger = setup_logger()
|
|
22
|
+
logger: logging.Logger = setup_logger()
|
|
23
|
+
|
|
24
|
+
print(f.renderText("ImgByteSizer"))
|
|
19
25
|
|
|
20
|
-
parser = argparse.ArgumentParser(
|
|
26
|
+
parser: argparse.ArgumentParser = argparse.ArgumentParser(
|
|
21
27
|
description="Resize an image to match a target file size",
|
|
22
28
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
23
29
|
epilog="""
|
|
24
|
-
|
|
30
|
+
examples:
|
|
25
31
|
%(prog)s image.jpg 500KB # Resize to 500 KB
|
|
26
32
|
%(prog)s photo.png 2MB -o small_photo.png # Resize to 2 MB with custom output
|
|
27
33
|
%(prog)s image.jpg 100KB -f webp # Resize and convert to WebP
|
|
@@ -30,22 +36,33 @@ Examples:
|
|
|
30
36
|
""",
|
|
31
37
|
)
|
|
32
38
|
|
|
39
|
+
# Version
|
|
40
|
+
parser.add_argument("-v", "--version", action="store_true", help="Show version information")
|
|
41
|
+
|
|
33
42
|
parser.add_argument("image_path", nargs="?", help="Path to the input image")
|
|
34
43
|
parser.add_argument("target_size", nargs="?", help='Target file size (e.g., "1MB", "500KB")')
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
|
|
45
|
+
# Primary options
|
|
46
|
+
primary: argparse._ArgumentGroup = parser.add_argument_group("primary options")
|
|
47
|
+
primary.add_argument("-o", "--output", help="Output path (default: input_resized.ext)")
|
|
48
|
+
primary.add_argument("-f", "--format", choices=IMG_FORMATS, help="Output format")
|
|
49
|
+
|
|
50
|
+
# Advanced options
|
|
51
|
+
advanced: argparse._ArgumentGroup = parser.add_argument_group("advanced options")
|
|
52
|
+
advanced.add_argument("--min-dimension", type=int, help="Minimum width/height in pixels")
|
|
53
|
+
advanced.add_argument(
|
|
39
54
|
"--no-exact",
|
|
40
55
|
action="store_true",
|
|
41
56
|
help="Do not pad file to get exact target size",
|
|
42
57
|
)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
parser.
|
|
58
|
+
|
|
59
|
+
# Utility and debug
|
|
60
|
+
utility = parser.add_argument_group("utility")
|
|
61
|
+
utility.add_argument("--debug", action="store_true", help="Enable debug logging")
|
|
62
|
+
utility.add_argument("-q", "--quiet", action="store_true", help="Minimal output")
|
|
46
63
|
|
|
47
64
|
# Handle version flag before checking required arguments
|
|
48
|
-
args = parser.parse_args()
|
|
65
|
+
args: argparse.Namespace = parser.parse_args()
|
|
49
66
|
|
|
50
67
|
# Handle version request
|
|
51
68
|
if args.version:
|
|
@@ -66,19 +83,19 @@ Examples:
|
|
|
66
83
|
return 0
|
|
67
84
|
|
|
68
85
|
# Validate input file exists
|
|
69
|
-
image_path = Path(args.image_path)
|
|
86
|
+
image_path: Path = Path(args.image_path)
|
|
70
87
|
if not image_path.exists():
|
|
71
88
|
logger.error(f"Input file not found: {args.image_path}")
|
|
72
89
|
return 1
|
|
73
90
|
|
|
74
91
|
try:
|
|
75
|
-
target_bytes = parse_filesize(args.target_size)
|
|
92
|
+
target_bytes: int = parse_filesize(args.target_size)
|
|
76
93
|
except ValueError as e:
|
|
77
94
|
logger.error(f"Error: {e}")
|
|
78
95
|
return 1
|
|
79
96
|
|
|
80
97
|
try:
|
|
81
|
-
output_path = resize_to_target_filesize(
|
|
98
|
+
output_path: str = resize_to_target_filesize(
|
|
82
99
|
args.image_path,
|
|
83
100
|
target_bytes,
|
|
84
101
|
args.output,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|