Image Optimizer Action will automatically compress JPEG, PNG and GIF images in your repository using Crush.pics API. It works like this:
- Action will scan your pull request for JPEG, PNG & GIF files and then it will send them to Crush.pics API for compression.
- After images are compressed, Action will update pull request with compressed images.
- Compression report is added to pull request comments.
- Sign up for a free API key at Crush.pics
- Open or create the
.github/workflows/crush-pics.yml
file. - Paste in the following:
name: Crush images
on:
pull_request:
branches:
- master
paths:
- '**.jpg'
- '**.jpeg'
- '**.png'
- '**.gif'
jobs:
crush:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Crush images
uses: crush-pics/crush-pics-github-action@master
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
api-key: ${{ secrets.CRUSH_API_KEY }}
CRUSH_API_KEY
is your Crush.pics API key. Get one by creating a free account on Crush.pics
By default Image Optimizer will use our best available Balanced compression. However, if you’d like to change image compression mode or ignore specific file paths, read on.
Change the configuration options by adding a .github/crush-pics/config.json
file:
{
"compression_mode": "balanced",
"compression_level": 85,
"strip_tags": false
}
compression_mode
:lossy
,lossless
orbalanced
compression_level
represents the compression level. Integer value has to be in range 65-100strip_tags
removes optional metadata
NOTE: compression_level
setting valid for lossy
mode only. balanced
& lossless
will ignore it. If you leave it blank and use lossy
mode - Image Optimizer will use default compression level (85%).
Image Optimizer is designed to run for each Pull Request. In some repositories, images are seldom updated. To run the action only when images have changed, use GitHub Action’s on.pull_request.paths
workflow configuration:
name: Crush images
on:
pull_request:
paths:
- '**.jpg'
- '**.jpeg'
- '**.png'
- '**.gif'
The above workflow will only run when jpg
, png
or gif
files are changed.