A GitHub action that automatically compresses images in pull requests. Free and open-source alternative to imgbot.
✅ Fast, efficient and near-lossless compression
✅ Supports compressing SVG, PNG, JPG, GIF, WEBP, and AVIF
✅ Can export PNG, JPG and GIF to WEBP
✅ Can export PNG, JPG and WEBP to AVIF
✅ Highly customizable
✅ Supports GitHub Enterprise
This tool is completely free. If you enjoy the tool please help support us.
Create file .github/workflows/image-optimizer.yml
name: Compress Images
on:
pull_request:
paths:
- '**/*.svg'
- '**/*.png'
- '**/*.jpg'
- '**/*.jpeg'
- '**/*.gif'
- '**/*.webp'
- '**/*.avif'
jobs:
build:
if: github.event.pull_request.head.repo.full_name == github.repository
name: cadamsdev/image-optimizer-action
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Compress Images
id: compress-images
uses: cadamsdev/image-optimizer-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Create file .github/workflows/image-optimizer-manual.yml
name: Compress Images (Manual)
on: workflow_dispatch
jobs:
build:
name: cadamsdev/image-optimizer-action
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Compress Images
id: compress-images
uses: cadamsdev/image-optimizer-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Create New Pull Request If Needed
if: steps.compress-images.outputs.markdown_report != ''
uses: peter-evans/create-pull-request@v5
with:
title: Compressed Images
branch-suffix: timestamp
commit-message: Compressed Images
body: ${{ steps.compress-images.outputs.markdown_report }}
e.g
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
export-webp: true
export-avif: true
replace-original-after-export-webp: true
ignore-paths: |
src/assets/images/some-dir/**
src/assets/images/another-dir/**
Input | Description | Type | Default |
---|---|---|---|
github-token | The generated GitHub token | string (required) | '' |
debug | Enables verbose logging for easier debugging | boolean | false |
compress-png | Enables compressing PNGs | boolean | true |
compress-svg | Enables compressing SVGs | boolean | true |
compress-jpg | Enables compressing JPG / JPEGs | boolean | true |
compress-webp | Enables compressing WEBPs | boolean | true |
compress-avif | Enables compressing AVIFs | boolean | true |
export-webp | Converts PNG, JPG / JPEG into WEBP | boolean | false |
export-avif | Converts PNG, JPG / JPEG, WEBP into AVIF | boolean | false |
replace-original-after-export-webp | Replace original files after exporting WebP files | boolean | false |
ignore-paths | Paths of globs to prevent from processing | string[] | node_modules/** |
Make sure to check "Allow GitHub Actions to create and approve pull requests" if you're using the manual workflow.