imgbytesizer 0.2.6__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 (32) hide show
  1. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/.github/workflows/ci.yml +7 -7
  2. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/.github/workflows/publish.yml +21 -21
  3. imgbytesizer-0.2.8/CHANGELOG.md +169 -0
  4. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/PKG-INFO +9 -7
  5. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/README.md +5 -3
  6. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/pyproject.toml +3 -3
  7. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/src/imgbytesizer/resizer.py +22 -4
  8. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/tests/test_resizer.py +31 -1
  9. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/uv.lock +115 -184
  10. imgbytesizer-0.2.6/CHANGELOG.md +0 -181
  11. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/.flake8 +0 -0
  12. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/.gitignore +0 -0
  13. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/.style.yapf +0 -0
  14. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/.vscode/extensions.json +0 -0
  15. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/.vscode/settings.json +0 -0
  16. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/.vulture_ignore.py +0 -0
  17. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/LICENSE +0 -0
  18. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/cliff.toml +0 -0
  19. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/pytest.ini +0 -0
  20. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/scripts/check_version.py +0 -0
  21. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/scripts/release.sh +0 -0
  22. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/src/imgbytesizer/__init__.py +0 -0
  23. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/src/imgbytesizer/formatter.py +0 -0
  24. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/src/imgbytesizer/logger.py +0 -0
  25. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/src/imgbytesizer/main.py +0 -0
  26. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/src/imgbytesizer/py.typed +0 -0
  27. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/src/imgbytesizer/utils.py +0 -0
  28. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/tests/test_formatter.py +0 -0
  29. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/tests/test_logger.py +0 -0
  30. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/tests/test_main.py +0 -0
  31. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/tests/test_utils.py +0 -0
  32. {imgbytesizer-0.2.6 → imgbytesizer-0.2.8}/tox.ini +0 -0
@@ -19,25 +19,25 @@ 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
- python-version: "3.10"
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
- uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
40
+ uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
41
41
  with:
42
42
  files: ./coverage.xml
43
43
  fail_ci_if_error: true
@@ -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
- python-version: "3.10"
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
- python-version: "3.10"
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,13 +77,13 @@ 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
84
84
  path: dist/
85
85
 
86
- - uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
86
+ - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
87
87
  name: 🚀 Publish package
88
88
  with:
89
89
  user: __token__
@@ -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
@@ -0,0 +1,169 @@
1
+ # Changelog
2
+
3
+ All notable changes to imgbytesizer will be documented in this file.
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
20
+ ## [0.2.6] - 2026-04-14
21
+
22
+ ### 🐛 Bug Fixes
23
+
24
+ - Resolve ty type checker errors in logger and resizer
25
+
26
+ ### 💼 Other
27
+
28
+ - Migrate from poetry to uv
29
+ - Add release automation with git-cliff and release script
30
+
31
+ ### ⚙️ Miscellaneous Tasks
32
+
33
+ - Update CHANGELOG for v0.2.5 release date change to 2025-05-25
34
+ - Pin actions to commit SHAs and bump Python to 3.10
35
+ ## [0.2.5] - 2025-05-25
36
+
37
+ ### 📚 Documentation
38
+
39
+ - Add Quality Gate Status badge to README for better visibility of code quality
40
+
41
+ ### 🧪 Testing
42
+
43
+ - Add and improve tests for image setup, format conversion, and size adjustments
44
+
45
+ ### ⚙️ Miscellaneous Tasks
46
+
47
+ - Refactor resize_to_target_filesize; add image helpers for setup, format, scaling; improve clarity
48
+ ## [0.2.4] - 2025-05-19
49
+
50
+ ### ⚙️ Miscellaneous Tasks
51
+
52
+ - Switch from build to poetry for package building, add poetry.lock, and remove requirements files
53
+ - Update poetry.lock; adjust tox.ini for command order and cleanup
54
+ - Add CI workflow for automated testing and coverage reporting; update publish workflow for Poetry integration
55
+ - Add imgbytesizer script entry point in pyproject.toml
56
+ - Tidy up imports in logger, resizer, and test files for better readability
57
+ ## [0.2.3] - 2025-05-14
58
+
59
+ ### 🐛 Bug Fixes
60
+
61
+ - Update type checking to use 'ty', adjust file size formatting, and clean up logger setup
62
+
63
+ ### 🚜 Refactor
64
+
65
+ - Enhance type annotations, improve file size formatting, and streamline logger setup
66
+
67
+ ### 📚 Documentation
68
+
69
+ - Update README and main.py for consistent example formatting and added version flag
70
+
71
+ ### ⚙️ Miscellaneous Tasks
72
+
73
+ - Add script to sort requirements files and ensure consistent ordering
74
+ - Replace mypy type checker with 'ty' in VSCode extensions
75
+ - Add pyfiglet dependency, enhance type annotations in logger and main modules, and tidy up imports
76
+ - Add virtual environment setup in GitHub Actions for publish and test workflows
77
+ - Activate virtual environment in GitHub Actions for build, test, and lint jobs
78
+ - Activate virtual environment in publish workflow before version check
79
+ ## [0.2.2] - 2025-05-13
80
+
81
+ ### 🚜 Refactor
82
+
83
+ - Clean up formatter and logger by removing unused functions and consolidating imports
84
+
85
+ ### 🧪 Testing
86
+
87
+ - Add comprehensive tests for main functionality and resizer edge cases
88
+ - Add entrypoint test and improve utility tests for image handling
89
+
90
+ ### ⚙️ Miscellaneous Tasks
91
+
92
+ - Update Makefile and requirements for linting and formatting improvements
93
+ - Add GitHub Actions workflow for testing and linting, update file size formatting function
94
+ - Update Makefile to run tests with coverage and add pytest-cov to requirements
95
+ - Add requirements.txt installation step to GitHub Actions workflow
96
+ - Add editable install step for local development in GitHub Actions workflow
97
+ - Update codecov action to v5 and add token and verbose options in GitHub Actions workflow
98
+ - Remove isort from formatting and requirements, update code style in imports
99
+ - Add Codecov badge to README for better visibility of test coverage
100
+ - Update formatting and linting configurations, add YAPF style guide, and adjust flake8 settings
101
+ - Add mypy type checker and YAPF formatter to VSCode extensions
102
+ - Update Makefile and GitHub Actions for improved linting and type checking
103
+ ## [0.2.1] - 2025-05-12
104
+
105
+ ### 🚀 Features
106
+
107
+ - Enhance GitHub Actions workflow to create or update releases based on existence, improving asset handling
108
+ - Add testing framework with pytest, update Makefile for test execution, and configure flake8 for code style enforcement
109
+ - Update Makefile for improved linting and formatting, add ruff for linting and autofix, enhance type hints across the codebase
110
+ - Enhance image resizing logic with combined scaling and quality adjustment, improve error handling, and extend quality range for better results
111
+ - Add CI tests to GitHub Actions workflow, including Python setup and dependency installation
112
+
113
+ ### 🐛 Bug Fixes
114
+
115
+ - Update TAG_NAME assignment in GitHub Actions workflow to prioritize version_tag over github.ref_name for better release tagging
116
+ - Adjust _adjust_to_exact_size function to remove unnecessary parameter
117
+
118
+ ### 📚 Documentation
119
+
120
+ - Update README example output to reflect new image dimensions, sizes, and processing times for imgbytesizer
121
+
122
+ ### ⚙️ Miscellaneous Tasks
123
+
124
+ - Bump version to 0.2.1 in pyproject.toml and __init__.py
125
+ - Add requirements installation step in GitHub Actions workflow
126
+ - Update GitHub Actions workflow to use Makefile for testing and building
127
+ - Remove redundant test job from GitHub Actions workflow, simplifying CI process
128
+ ## [0.2.0] - 2025-05-10
129
+
130
+ ### 🚀 Features
131
+
132
+ - Add version check script and enhance GitHub Actions workflow for dependency installation and version validation
133
+ - Bump version to 0.2.0, add author and description, enhance logging and terminal output features
134
+ - Add vulture ignore file, enhance Makefile for linting, and update dev dependencies
135
+ - Update CHANGELOG for version 0.2.0, document new features, changes, and fixes
136
+ - Improve JPEG handling in _adjust_to_exact_size function
137
+
138
+ ### 📚 Documentation
139
+
140
+ - Update README with new command-line options and example output for imgbytesizer
141
+
142
+ ### ⚙️ Miscellaneous Tasks
143
+
144
+ - Add Makefile for build and lint tasks, update development dependencies
145
+ ## [0.1.0] - 2025-05-09
146
+
147
+ ### 🚀 Features
148
+
149
+ - Init commit with setup files
150
+ - Enhance image resizing tool with progress indicators and detailed output
151
+ - Add LICENSE and project metadata for imgbytesizer CLI tool
152
+ - Add GitHub Actions workflow for automated release publishing
153
+ - Implement core functionality for imgbytesizer CLI tool with image resizing and utility functions
154
+ - Enhance GitHub Actions workflow to support manual version tagging and improve release asset handling
155
+
156
+ ### 🐛 Bug Fixes
157
+
158
+ - Update Python version requirement to 3.9
159
+
160
+ ### 📚 Documentation
161
+
162
+ - Add README.md with usage instructions, features, and examples for ImgByteSizer
163
+ - Add CHANGELOG.md for version 0.1.0 with initial release details
164
+
165
+ ### ⚙️ Miscellaneous Tasks
166
+
167
+ - Add .gitignore file to exclude unnecessary files from version control
168
+ - Add VSCode extensions recommendations for Python development
169
+ - Update dependencies to use requirements-dev.txt for development and remove outdated build dependency from requirements.txt
@@ -1,13 +1,13 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: imgbytesizer
3
- Version: 0.2.6
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
7
7
  License-File: LICENSE
8
8
  Keywords: cli,compression,image,optimize,resize
9
- Requires-Python: >=3.10
10
- Requires-Dist: pillow<13.0.0,>=12.2.0
9
+ Requires-Python: >=3.11
10
+ Requires-Dist: pillow<14.0.0,>=13.0.0
11
11
  Requires-Dist: pyfiglet<2.0.0,>=1.0.2
12
12
  Requires-Dist: tabulate<0.10.0,>=0.9.0
13
13
  Description-Content-Type: text/markdown
@@ -15,7 +15,7 @@ Description-Content-Type: text/markdown
15
15
  # ImgByteSizer
16
16
 
17
17
  [![PyPI version](https://img.shields.io/pypi/v/imgbytesizer.svg)](https://pypi.org/project/imgbytesizer/)
18
- [![PyPI Downloads](https://static.pepy.tech/badge/imgbytesizer)](https://pepy.tech/projects/imgbytesizer)
18
+ [![PyPI Downloads](https://img.shields.io/pypi/dm/imgbytesizer.svg)](https://pypistats.org/packages/imgbytesizer)
19
19
  [![codecov](https://codecov.io/gh/pyyupsk/imgbytesizer/graph/badge.svg?token=GJH6N3ZAJS)](https://codecov.io/gh/pyyupsk/imgbytesizer)
20
20
  [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=pyyupsk_imgbytesizer&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=pyyupsk_imgbytesizer)
21
21
 
@@ -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
@@ -1,7 +1,7 @@
1
1
  # ImgByteSizer
2
2
 
3
3
  [![PyPI version](https://img.shields.io/pypi/v/imgbytesizer.svg)](https://pypi.org/project/imgbytesizer/)
4
- [![PyPI Downloads](https://static.pepy.tech/badge/imgbytesizer)](https://pepy.tech/projects/imgbytesizer)
4
+ [![PyPI Downloads](https://img.shields.io/pypi/dm/imgbytesizer.svg)](https://pypistats.org/packages/imgbytesizer)
5
5
  [![codecov](https://codecov.io/gh/pyyupsk/imgbytesizer/graph/badge.svg?token=GJH6N3ZAJS)](https://codecov.io/gh/pyyupsk/imgbytesizer)
6
6
  [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=pyyupsk_imgbytesizer&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=pyyupsk_imgbytesizer)
7
7
 
@@ -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.6"
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
 
@@ -9,10 +9,10 @@ authors = [{ name = "pyyupsk", email = "contact@fasu.dev" }]
9
9
  readme = "README.md"
10
10
  license = { text = "MIT License" }
11
11
 
12
- requires-python = ">=3.10"
12
+ requires-python = ">=3.11"
13
13
 
14
14
  dependencies = [
15
- "pillow>=12.2.0,<13.0.0",
15
+ "pillow>=13.0.0,<14.0.0",
16
16
  "pyfiglet>=1.0.2,<2.0.0",
17
17
  "tabulate>=0.9.0,<0.10.0",
18
18
  ]
@@ -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