Skip to content
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

feature(pre-commit): image compression hook , WIP #47

Closed
wants to merge 1 commit into from

Conversation

Mellywins
Copy link
Collaborator

Initial Draft PR for the image compression pre-commit

This PR will be the start of the changes made to:

  1. Add pre-commit hook via husky
  2. Implement image conversion to webp, 80% lossless quality cropping

# If Host is linux, install imagemagick
if [ "$(uname)" == "Linux" ]; then
echo >&2 "Installing imagemagick..."
sudo apt-get install imagemagick
Copy link
Owner

Choose a reason for hiding this comment

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

Not platform agnostic
Use imagemagick binary and copy it to ~/.bin and make it executable

fi
# If Host Is Windows, install imagemagick
if [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
echo >&2 "May god have mercy on your soul..."
Copy link
Owner

Choose a reason for hiding this comment

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

Please use a real OS**

@wadhah101
Copy link
Owner

✝✝✝✝✝

@wadhah101
Copy link
Owner

Define your script in separate .sh to make it reusable.

Is this script idempotent ?

Make sure image quality settings are configurable without modifying the code
Make sure to define the script scope with a variable and make some test images / MD files

This was linked to issues Nov 9, 2022
@wadhah101 wadhah101 added the enhancement New feature or request label Nov 9, 2022
@wadhah101 wadhah101 removed a link to an issue Nov 13, 2022
@wadhah101
Copy link
Owner

wadhah101 commented Nov 14, 2022

Proposal so this works perfectly with pre-commit :

  • Don't attempt to install imagemagick, installing it is out of scope for this PR
  • assume $1 contains image filename, make sure to skip not to fail if it's not an image ( don't rely on file extensions )
  • don't perform full search when replacing image name, just change extension to webp
  • add quality flag with default quality=90 to the script
  • avoid manual confirmation or add --confirm flag

Don't forget to use https://github.com/koalaman/shellcheck to ensure code quality 🔥

@wadhah101 wadhah101 closed this Jan 21, 2023
@wadhah101 wadhah101 deleted the precommit-setup branch January 21, 2023 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize images at repository for better storage
2 participants