Open
Conversation
Also added dev requirements file that includes Pillow required for the script to run.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a developer-facing image optimization workflow to the Weekly Dev Chat MkDocs site, enabling contributors to convert post images to WebP and resize them before committing.
Changes:
- Added
scripts/optimize_image.pyto convert images to WebP, optionally resize to a max width, and print size savings. - Introduced dev-only Pillow dependencies via
requirements-dev.in/requirements-dev.txt. - Documented the new image optimization process in
README.mdandAGENTS.md.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/optimize_image.py | New CLI script to convert/resize images and report savings. |
| requirements-dev.in | Adds dev-only dependency intent for Pillow. |
| requirements-dev.txt | Adds compiled/pinned dev dependency for Pillow. |
| README.md | Documents how/when to run the image optimization script and adds it to common commands/project structure. |
| AGENTS.md | Updates blog post rules to include running the optimization script. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
Tested on Linux mint. Works great. 611k image reduced to 67k. |
WebP files are already optimized. Accepting them as input caused
with_suffix('.webp') to resolve to the same path, overwriting the
original and making the size comparison incorrect.
Fixes review feedback on PR #106.
- Add .python-version file (for pyenv/uv) pinning to 3.14 - Add runtime version guard in scripts/optimize_image.py that exits with a clear error if run on Python < 3.14 Addresses review feedback on PR #106.
Python 3.14 supports X | Y union syntax natively (PEP 604), so the lazy annotation evaluation from PEP 563 is no longer required.
CRLF line endings caused 'python3\r: No such file or directory' when running the script in Docker (Linux). Strip to LF and add .gitattributes to enforce LF for .py and .sh files going forward.
Add ImageOps.exif_transpose() call after opening the image so that JPEGs with EXIF Orientation metadata are correctly rotated/flipped before mode conversion and resizing. Without this, output WebPs could appear rotated compared to the original. Fixes review feedback on PR #106.
Add _quality_int and _positive_int type helpers so invalid CLI arguments (quality outside 1–100, max-width <= 0) fail immediately with a clear error message instead of causing cryptic Pillow errors. Fixes review feedback on PR #106.
Update requirements-dev.txt header from pip-compile/Python 3.9 to match the uv pip compile format used elsewhere in the repo. Also clarify the regenerate command comment in requirements-dev.in. Fixes review feedback on PR #106.
Member
Author
|
@normanlorrain and @o-ashour I made some changes based on the Copilot PR feedback. Let me know if you have any other improvements for the script. I am going to optimize all the images in the project but in a separate PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce an image optimization script that converts images to WebP format and resizes them for web use.