imgbytesizer 0.2.7__tar.gz → 0.2.8__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.
Files changed (31) hide show
  1. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/.github/workflows/ci.yml +5 -5
  2. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/.github/workflows/publish.yml +18 -18
  3. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/CHANGELOG.md +15 -0
  4. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/PKG-INFO +5 -3
  5. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/README.md +4 -2
  6. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/pyproject.toml +1 -1
  7. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/src/imgbytesizer/resizer.py +22 -4
  8. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/tests/test_resizer.py +31 -1
  9. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/uv.lock +4 -4
  10. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/.flake8 +0 -0
  11. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/.gitignore +0 -0
  12. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/.style.yapf +0 -0
  13. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/.vscode/extensions.json +0 -0
  14. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/.vscode/settings.json +0 -0
  15. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/.vulture_ignore.py +0 -0
  16. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/LICENSE +0 -0
  17. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/cliff.toml +0 -0
  18. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/pytest.ini +0 -0
  19. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/scripts/check_version.py +0 -0
  20. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/scripts/release.sh +0 -0
  21. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/src/imgbytesizer/__init__.py +0 -0
  22. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/src/imgbytesizer/formatter.py +0 -0
  23. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/src/imgbytesizer/logger.py +0 -0
  24. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/src/imgbytesizer/main.py +0 -0
  25. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/src/imgbytesizer/py.typed +0 -0
  26. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/src/imgbytesizer/utils.py +0 -0
  27. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/tests/test_formatter.py +0 -0
  28. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/tests/test_logger.py +0 -0
  29. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/tests/test_main.py +0 -0
  30. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/tests/test_utils.py +0 -0
  31. {imgbytesizer-0.2.7 → imgbytesizer-0.2.8}/tox.ini +0 -0
@@ -19,22 +19,22 @@ jobs:
19
19
  ci:
20
20
  runs-on: ubuntu-latest
21
21
  steps:
22
- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
22
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
23
23
  name: ⬇️ Checkout repository
24
24
 
25
- - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
25
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
26
26
  name: 📦 Setup Python
27
27
  with:
28
28
  python-version: "3.11"
29
29
 
30
- - uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0
30
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
31
31
  name: 📦 Setup uv
32
32
 
33
33
  - name: 🔍 Install dependencies
34
- run: uv sync
34
+ run: uv sync --locked --no-build
35
35
 
36
36
  - name: 🧪 Run tests
37
- run: uv run tox
37
+ run: uv run --locked --no-build tox
38
38
 
39
39
  - name: 📊 Upload coverage
40
40
  uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
@@ -22,46 +22,46 @@ jobs:
22
22
  check-version:
23
23
  runs-on: ubuntu-latest
24
24
  steps:
25
- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
25
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
26
26
  name: ⬇️ Checkout repository
27
27
 
28
- - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
28
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
29
29
  name: 📦 Setup Python
30
30
  with:
31
31
  python-version: "3.11"
32
32
 
33
- - uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0
33
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
34
34
  name: 📦 Setup uv
35
35
 
36
36
  - name: 🔍 Install dependencies
37
- run: uv sync
37
+ run: uv sync --locked --no-build
38
38
 
39
39
  - name: 🔍 Check version is not already published on PyPI
40
- run: uv run python scripts/check_version.py
40
+ run: uv run --locked --no-build python scripts/check_version.py
41
41
 
42
42
  release-build:
43
43
  runs-on: ubuntu-latest
44
44
  needs:
45
45
  - check-version
46
46
  steps:
47
- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
47
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
48
48
  name: ⬇️ Checkout repository
49
49
 
50
- - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
50
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
51
51
  name: 📦 Setup Python
52
52
  with:
53
53
  python-version: "3.11"
54
54
 
55
- - uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57 # v8.0.0
55
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
56
56
  name: 📦 Setup uv
57
57
 
58
58
  - name: 🔍 Install dependencies
59
- run: uv sync
59
+ run: uv sync --locked --no-build
60
60
 
61
61
  - name: 🏗 Build release
62
- run: uv run tox -e build
62
+ run: uv run --locked --no-build tox -e build
63
63
 
64
- - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
64
+ - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
65
65
  name: 📤 Upload artifact
66
66
  with:
67
67
  name: release
@@ -77,7 +77,7 @@ jobs:
77
77
  name: pypi
78
78
  url: https://pypi.org/project/imgbytesizer
79
79
  steps:
80
- - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
80
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
81
81
  name: 📥 Download artifact
82
82
  with:
83
83
  name: release
@@ -97,18 +97,18 @@ jobs:
97
97
  contents: write
98
98
  id-token: write
99
99
  steps:
100
- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
100
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
101
101
  name: ⬇️ Checkout repository
102
102
  with:
103
103
  fetch-depth: 0
104
104
 
105
- - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
105
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
106
106
  name: 📥 Download artifact
107
107
  with:
108
108
  name: release
109
109
  path: dist/
110
110
 
111
- - uses: sigstore/gh-action-sigstore-python@04cffa1d795717b140764e8b640de88853c92acc # v3.3.0
111
+ - uses: sigstore/gh-action-sigstore-python@790bc6befb9d733738f18d8f895854b453640ec9 # v3.5.0
112
112
  name: 🔑 Sign artifact
113
113
  with:
114
114
  inputs: dist/*
@@ -129,7 +129,7 @@ jobs:
129
129
  fi
130
130
 
131
131
  - name: 📝 Generate release notes
132
- uses: orhun/git-cliff-action@c93ef52f3d0ddcdcc9bd5447d98d458a11cd4f72 # v4.7.1
132
+ uses: orhun/git-cliff-action@a9a95522b26fe6403f7bb24031f21fb573d0f5ff # v4.9.1
133
133
  id: changelog
134
134
  with:
135
135
  config: cliff.toml
@@ -154,14 +154,14 @@ jobs:
154
154
  permissions:
155
155
  contents: write
156
156
  steps:
157
- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
157
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
158
158
  name: ⬇️ Checkout repository
159
159
  with:
160
160
  fetch-depth: 0
161
161
  ref: main
162
162
 
163
163
  - name: 📝 Generate full changelog
164
- uses: orhun/git-cliff-action@c93ef52f3d0ddcdcc9bd5447d98d458a11cd4f72 # v4.7.1
164
+ uses: orhun/git-cliff-action@a9a95522b26fe6403f7bb24031f21fb573d0f5ff # v4.9.1
165
165
  with:
166
166
  config: cliff.toml
167
167
  args: --output CHANGELOG.md
@@ -2,6 +2,21 @@
2
2
 
3
3
  All notable changes to imgbytesizer will be documented in this file.
4
4
 
5
+ ## [0.2.7] - 2026-11-02
6
+
7
+ ### 🐛 Bug Fixes
8
+
9
+ - Bump pillow to 12.3.0, update uv.lock to resolve 28 dependabot vulns
10
+ - Bump pillow to 13.0.0 and drop python 3.10 to resolve dependabot alerts (#2)
11
+
12
+ ### 📚 Documentation
13
+
14
+ - Update CHANGELOG.md for v0.2.6
15
+ - Switch download badge from pepy to shields.io pypistats
16
+
17
+ ### ⚙️ Miscellaneous Tasks
18
+
19
+ - Bump pypi-publish action to v1.14.3 for metadata 2.5 support
5
20
  ## [0.2.6] - 2026-04-14
6
21
 
7
22
  ### 🐛 Bug Fixes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: imgbytesizer
3
- Version: 0.2.7
3
+ Version: 0.2.8
4
4
  Summary: A CLI tool to resize images to a target file size.
5
5
  Author-email: pyyupsk <contact@fasu.dev>
6
6
  License: MIT License
@@ -45,6 +45,8 @@ imgbytesizer image.jpg 500KB
45
45
 
46
46
  ### Basic Examples
47
47
 
48
+ A supported extension in `--output` selects the format. Use `--format` to override it.
49
+
48
50
  ```bash
49
51
  # Resize an image to 500KB
50
52
  imgbytesizer large_photo.jpg 500KB
@@ -52,8 +54,8 @@ imgbytesizer large_photo.jpg 500KB
52
54
  # Resize and convert to WebP format
53
55
  imgbytesizer image.png 1MB -f webp
54
56
 
55
- # Specify output file path
56
- imgbytesizer photo.jpg 1MB -o compressed_photo.jpg
57
+ # Specify the output path and infer WebP from its extension
58
+ imgbytesizer photo.jpg 1MB -o compressed_photo.webp
57
59
 
58
60
  # Ensure minimum dimension is at least 400px
59
61
  imgbytesizer large_image.jpg 300KB --min-dimension 400
@@ -31,6 +31,8 @@ imgbytesizer image.jpg 500KB
31
31
 
32
32
  ### Basic Examples
33
33
 
34
+ A supported extension in `--output` selects the format. Use `--format` to override it.
35
+
34
36
  ```bash
35
37
  # Resize an image to 500KB
36
38
  imgbytesizer large_photo.jpg 500KB
@@ -38,8 +40,8 @@ imgbytesizer large_photo.jpg 500KB
38
40
  # Resize and convert to WebP format
39
41
  imgbytesizer image.png 1MB -f webp
40
42
 
41
- # Specify output file path
42
- imgbytesizer photo.jpg 1MB -o compressed_photo.jpg
43
+ # Specify the output path and infer WebP from its extension
44
+ imgbytesizer photo.jpg 1MB -o compressed_photo.webp
43
45
 
44
46
  # Ensure minimum dimension is at least 400px
45
47
  imgbytesizer large_image.jpg 300KB --min-dimension 400
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "imgbytesizer"
3
- version = "0.2.7"
3
+ version = "0.2.8"
4
4
  description = "A CLI tool to resize images to a target file size."
5
5
  keywords = ["image", "resize", "compression", "cli", "optimize"]
6
6
 
@@ -15,7 +15,7 @@ from .formatter import format_filesize
15
15
  from .logger import (
16
16
  Colors, print_comparison_table, print_processing_step, print_progress_bar, print_result
17
17
  )
18
- from .utils import get_file_size_bytes, get_output_format, get_output_path
18
+ from .utils import IMG_FORMATS, get_file_size_bytes, get_output_format, get_output_path
19
19
 
20
20
  # Allow loading truncated images
21
21
  ImageFile.LOAD_TRUNCATED_IMAGES = True # ty: ignore[invalid-assignment]
@@ -24,6 +24,16 @@ ImageFile.LOAD_TRUNCATED_IMAGES = True # ty: ignore[invalid-assignment]
24
24
  logger: logging.Logger = logging.getLogger("imgbytesizer")
25
25
 
26
26
 
27
+ def _resolve_path(path: str) -> str:
28
+ """Resolve a user-supplied path to an absolute, normalized path."""
29
+ # Resolve only the directory so a symlinked file keeps its own name and extension.
30
+ resolved: Path = Path(path).parent.resolve() / Path(path).name
31
+ # Every resolved path sits under its own anchor; this is the check taint analysis expects.
32
+ if not resolved.is_relative_to(resolved.anchor):
33
+ raise ValueError(f"Invalid path: {path}")
34
+ return str(resolved)
35
+
36
+
27
37
  def _setup_image(image_path: Union[str, Path],
28
38
  quiet: bool = False) -> Tuple[Image.Image, int, int, int]:
29
39
  """Load image and get original info."""
@@ -60,7 +70,7 @@ def _handle_format_conversion(
60
70
  ) -> str:
61
71
  """Handle format conversion if needed."""
62
72
  if format_name and format_name.upper() != img.format:
63
- img.save(output_path)
73
+ img.save(output_path, format=format_name)
64
74
  if not quiet:
65
75
  print_result("Status", "Converted format only", "good")
66
76
  print_result("Output", os.path.basename(output_path))
@@ -154,8 +164,14 @@ def resize_to_target_filesize(
154
164
  img, orig_width, orig_height, orig_size = _setup_image(image_path, quiet)
155
165
 
156
166
  # Normalize format names and determine output path
167
+ output_extension = Path(output_path).suffix.lower().removeprefix(".") if output_path else ""
168
+ if format_name is None and output_extension in IMG_FORMATS:
169
+ format_name = output_extension
170
+
157
171
  pil_format: str = get_output_format(img.format or "JPEG", format_name)
158
- output_path = get_output_path(image_path, output_path, pil_format)
172
+ output_path = _resolve_path(get_output_path(image_path, output_path, pil_format))
173
+ if pil_format == "JPEG" and img.mode not in ("L", "RGB", "CMYK"):
174
+ img = img.convert("RGB")
159
175
 
160
176
  if not quiet:
161
177
  print_result("Format", pil_format)
@@ -165,7 +181,9 @@ def resize_to_target_filesize(
165
181
  if orig_size <= target_size_bytes:
166
182
  if not quiet:
167
183
  print(f"{Colors.GREEN}✓ Original image is already smaller than target size{Colors.ENDC}")
168
- return _handle_format_conversion(img, str(image_path), output_path, format_name, quiet)
184
+ result = _handle_format_conversion(img, str(image_path), output_path, pil_format, quiet)
185
+ if os.path.getsize(result) <= target_size_bytes:
186
+ return result
169
187
 
170
188
  # Select and execute resizing strategy
171
189
  result = _select_resizing_strategy(
@@ -7,7 +7,7 @@ from imgbytesizer.resizer import (
7
7
  _adjust_final_size, _adjust_to_exact_size, _apply_min_dimension_constraint,
8
8
  _binary_search_scale, _final_quality_adjustment, _find_best_quality, _handle_format_conversion,
9
9
  _try_combined_approach, _try_minimum_size, _try_quality_adjustment, _try_resizing,
10
- _try_scale_with_quality, resize_to_target_filesize, _setup_image
10
+ _try_scale_with_quality, resize_to_target_filesize, _resolve_path, _setup_image
11
11
  )
12
12
 
13
13
 
@@ -408,3 +408,33 @@ def test_adjust_to_exact_size_padding(sample_image):
408
408
  _adjust_to_exact_size(output_path, target_size, quiet=True)
409
409
  assert os.path.getsize(output_path) == target_size
410
410
  os.remove(output_path)
411
+
412
+
413
+ def test_resolve_path(tmp_path, monkeypatch):
414
+ # Relative paths become absolute; a symlinked file keeps its own name
415
+ monkeypatch.chdir(tmp_path)
416
+ (tmp_path / "target.jpg").touch()
417
+ (tmp_path / "out.png").symlink_to(tmp_path / "target.jpg")
418
+ assert _resolve_path("x.jpg") == str(tmp_path.resolve() / "x.jpg")
419
+ assert _resolve_path("out.png") == str(tmp_path.resolve() / "out.png")
420
+
421
+
422
+ @pytest.mark.parametrize("target_size", [12 * 1024, 1024 * 1024])
423
+ @pytest.mark.parametrize(
424
+ ("filename", "format_name", "expected_format"),
425
+ [("output.JPG", None, "JPEG"), ("output.jpg", "webp", "WEBP")],
426
+ )
427
+ def test_output_format_matches_requested_destination(
428
+ tmp_path, target_size, filename, format_name, expected_format
429
+ ):
430
+ input_path = tmp_path / "input.png"
431
+ output_path = tmp_path / filename
432
+ Image.effect_noise((320, 240), 65).convert("RGBA").save(input_path)
433
+
434
+ resize_to_target_filesize(
435
+ input_path, target_size, output_path=str(output_path), format_name=format_name, quiet=True
436
+ )
437
+
438
+ with Image.open(output_path) as image:
439
+ assert image.format == expected_format
440
+ assert output_path.stat().st_size <= target_size
@@ -265,7 +265,7 @@ wheels = [
265
265
 
266
266
  [[package]]
267
267
  name = "imgbytesizer"
268
- version = "0.2.7"
268
+ version = "0.2.8"
269
269
  source = { editable = "." }
270
270
  dependencies = [
271
271
  { name = "pillow" },
@@ -664,11 +664,11 @@ wheels = [
664
664
 
665
665
  [[package]]
666
666
  name = "urllib3"
667
- version = "2.7.0"
667
+ version = "2.8.0"
668
668
  source = { registry = "https://pypi.org/simple" }
669
- sdist = { url = "https://files.pythonhosted.org/packages/53/0c/06f8b233b8fd13b9e5ee11424ef85419ba0d8ba0b3138bf360be2ff56953/urllib3-2.7.0.tar.gz", hash = "sha256:231e0ec3b63ceb14667c67be60f2f2c40a518cb38b03af60abc813da26505f4c", size = 433602, upload-time = "2026-05-07T16:13:18.596Z" }
669
+ sdist = { url = "https://files.pythonhosted.org/packages/e3/05/b17359e1cefb4f909b5e40b1b90a496d987258916dbbf88e842c729f510e/urllib3-2.8.0.tar.gz", hash = "sha256:63bf2ead4c879426ebf22ef2a781eeb4aa3b4ae798a0435506f8687fd5bb9b63", size = 458972, upload-time = "2026-09-15T19:29:36.253Z" }
670
670
  wheels = [
671
- { url = "https://files.pythonhosted.org/packages/7f/3e/5db95bcf282c52709639744ca2a8b149baccf648e39c8cc87553df9eae0c/urllib3-2.7.0-py3-none-any.whl", hash = "sha256:9fb4c81ebbb1ce9531cce37674bbc6f1360472bc18ca9a553ede278ef7276897", size = 131087, upload-time = "2026-05-07T16:13:17.151Z" },
671
+ { url = "https://files.pythonhosted.org/packages/92/9d/c4e665119135114480843e7ab388fa94d8480650450e6f8e26b70d323a4c/urllib3-2.8.0-py3-none-any.whl", hash = "sha256:0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3", size = 135717, upload-time = "2026-09-15T19:29:34.577Z" },
672
672
  ]
673
673
 
674
674
  [[package]]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes