https://github.com/cadamsdev/image-optimizer-action
A GitHub action that automatically compresses SVG, PNG, JPG, GIF, WEBP, and AVIF in pull requests. Free and open-source alternative to imgbot.
https://github.com/cadamsdev/image-optimizer-action
avif compress-images compression github-action github-actions image image-compression imgbot optimizer performance sharp webp
Last synced: 6 months ago
JSON representation
A GitHub action that automatically compresses SVG, PNG, JPG, GIF, WEBP, and AVIF in pull requests. Free and open-source alternative to imgbot.
- Host: GitHub
- URL: https://github.com/cadamsdev/image-optimizer-action
- Owner: cadamsdev
- License: gpl-3.0
- Created: 2024-11-26T02:37:25.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-02-27T02:12:14.000Z (7 months ago)
- Last Synced: 2025-03-26T15:21:18.247Z (6 months ago)
- Topics: avif, compress-images, compression, github-action, github-actions, image, image-compression, imgbot, optimizer, performance, sharp, webp
- Language: TypeScript
- Homepage:
- Size: 418 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Image Optimizer Action
[](https://github.com/cadamsdev/notes/issues) [](https://www.gnu.org/licenses/gpl-3.0) 
A GitHub action that automatically compresses images in pull requests. Free and open-source alternative to [imgbot](https://imgbot.net/).
## ✨ Features
✅ 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](#configuration)
✅ Supports GitHub Enterprise
[View On GitHub Marketplace](https://github.com/marketplace/actions/image-optimizer-action)
This tool is completely free. If you enjoy the tool please help support us.
[](https://www.buymeacoffee.com/cadamsdev)
# 📚 Table of Contents
1. [Media](#media)
2. [Usage](#usage)
3. [Configuration](#configuration)
4. [Permissions](#permissions)## 🖼️ Media

## 🚀 Usage
### Pull request workflow
Create file .github/workflows/image-optimizer.yml
```yml
name: Compress Imageson:
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: Compress Images
id: compress-images
uses: cadamsdev/image-optimizer-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
```### Manual Workflow
Create file .github/workflows/image-optimizer-manual.yml
```yml
name: Compress Images (Manual)on: workflow_dispatch
jobs:
build:
name: cadamsdev/image-optimizer-action
permissions: write-all
runs-on: ubuntu-lateststeps:
- name: Checkout Repo
uses: actions/checkout@v4- 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 }}
```## 🔧 Configuration
e.g
```yml
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/\*\* |## 🔒 Permissions
Make sure to check "Allow GitHub Actions to create and approve pull requests" if you're using the manual workflow.
