Skip to content

Simple image resize scripts #713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

TimOsahenru
Copy link
Contributor

@TimOsahenru TimOsahenru commented Jun 13, 2025

Issue Link 🔗:

Issue: #711

Type of Change

  • Bug fix 🐞
  • New feature/page
  • Documentation update
  • Other

Description 📋

The script is ran with the command python3 image_resize.py from the root directory i.e where the requirements.txt file is located.

update

  • Added rules for cropping, resizing, and webp conversion
  • Automatically crop banners/headers to 16:9 (max 1920x1080) and thumbs/profiles to 1:1 (max 800x800)
  • Convert non-transparent images to optimized webp
  • Preserve aspect ratio with centered cropping (no distortion)
  • Default unmatched images to 800x600 (no forced upscaling)

Checklist ✅

  • Followed the Code of Conduct and Contribution Guide
  • Ran pre-commit run --all
  • All tests pass locally
  • Added tests (if applicable)
  • Documentation updated (if applicable)

Additional Notes & Screenshots

image

@TimOsahenru TimOsahenru requested a review from kjaymiller June 13, 2025 16:08
image_resize.py Outdated
import os

folder = "assets/images"
new_size = (800, 600)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this force all images to be 800 x 600?

Is there a way to crop these to the correct ratio before resizing. My worry is that images would be warped or distorted.

@kjaymiller
Copy link
Contributor

@TimOsahenru thank you so much for looking into this!

Have you seen this? https://github.com/boidolr/pre-commit-images? My thoughts were definitely to make scaling changes where necessary.

Here is a list of the things that I would like to see down in this

  • resize all banner style images to 16:9 ratio with minimum
  • resize thumbnail and people photos to 1:1 with maximum size TBD.
  • all images that don't need transparent backgrounds be converted to webp and optimized

@TimOsahenru
Copy link
Contributor Author

Hello @kjaymiller please check this out again, I've improved the script to meet your request

@TimOsahenru TimOsahenru merged commit 6134625 into BlackPythonDevs:gh-pages Jun 20, 2025
0 of 3 checks passed
@TimOsahenru TimOsahenru deleted the script_for_resizing_images branch June 20, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants