Skip to content

Add image optimization script#106

Open
mrbiggred wants to merge 9 commits intomainfrom
feature/script-to-optimize-image
Open

Add image optimization script#106
mrbiggred wants to merge 9 commits intomainfrom
feature/script-to-optimize-image

Conversation

@mrbiggred
Copy link
Copy Markdown
Member

Introduce an image optimization script that converts images to WebP format and resizes them for web use.

Also added dev requirements file that includes Pillow required for the script to run.
@mrbiggred mrbiggred marked this pull request as draft April 7, 2026 16:05
@mrbiggred mrbiggred requested a review from Copilot April 7, 2026 16:05
@mrbiggred mrbiggred self-assigned this Apr 7, 2026
@mrbiggred mrbiggred added the devops DevOps tasks label Apr 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py to 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.md and AGENTS.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.

Comment thread scripts/optimize_image.py
Comment thread scripts/optimize_image.py
Comment thread scripts/optimize_image.py
Comment thread scripts/optimize_image.py
Comment thread scripts/optimize_image.py
Comment thread requirements-dev.txt Outdated
Comment thread requirements-dev.in Outdated
@normanlorrain
Copy link
Copy Markdown
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.
@mrbiggred
Copy link
Copy Markdown
Member Author

mrbiggred commented Apr 17, 2026

@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.

@mrbiggred mrbiggred marked this pull request as ready for review April 17, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devops DevOps tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants